Repository navigation
Closed
Labels
Description
Describe the bug
Static library compiled as custom_target() is missing from dependencies.
Reproduced on current master 7824ff8
Bisected to a78af23
To Reproduce
meson.build:
project('repro', 'c')
s1 = custom_target('s1',
command: [
find_program('compile.sh'),
'@CURRENT_SOURCE_DIR@',
meson.current_build_dir(),
'@PRIVATE_DIR@',
],
output: 'libs1.a',
)
s2 = static_library('s2',
's2.c',
link_with: s1,
install: true,
)
main = executable('main',
'main.c',
link_with: s2,
)s1.c:
int s1(void)
{
return 42;
}s2.c:
int s1(void);
int s2(void)
{
return s1();
}main.c:
int s2(void);
int main(int argc, char *argv[])
{
return s2();
}compile.sh:
#!/bin/sh
CURRENT_SOURCE_DIR=$1
CURRENT_BUILD_DIR=$2
PRIVATE_DIR=$3
mkdir -p "$PRIVATE_DIR"
cc -c -o "$PRIVATE_DIR"/s1.o "$CURRENT_SOURCE_DIR"/s1.c
ar rcs "$CURRENT_BUILD_DIR"/libs1.a "$PRIVATE_DIR"/s1.o
Expected behaviour
[1/5] ccache cc -Ilibs2.a.p -I. -I../../../testmesonstaticlink -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -O0 -g -fPIC -MD -MQ libs2.a.p/s2.c.o -MF libs2.a.p/s2.c.o.d -o libs2.a.p/s2.c.o -c ../../../testmesonstaticlink/s2.c
[2/5] ccache cc -Imain.p -I. -I../../../testmesonstaticlink -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -O0 -g -MD -MQ main.p/main.c.o -MF main.p/main.c.o.d -o main.p/main.c.o -c ../../../testmesonstaticlink/main.c
[3/5] rm -f libs2.a && gcc-ar csrD libs2.a libs2.a.p/s2.c.o
[4/5] /home/woju/testmesonstaticlink/compile.sh ../../../testmesonstaticlink/ /home/woju/src/meson/build-test libs1.a.p
[5/5] cc -o main main.p/main.c.o -Wl,--as-needed -Wl,--no-undefined '-Wl,-rpath,$ORIGIN/' -Wl,-rpath-link,/home/woju/src/meson/build-test/ -Wl,--start-group libs2.a libs1.a -Wl,--end-group
Actual behaviour
[1/4] ccache cc -Ilibs2.a.p -I. -I../../../testmesonstaticlink -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -O0 -g -fPIC -MD -MQ libs2.a.p/s2.c.o -MF libs2.a.p/s2.c.o.d -o libs2.a.p/s2.c.o -c ../../../testmesonstaticlink/s2.c
[2/4] ccache cc -Imain.p -I. -I../../../testmesonstaticlink -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -O0 -g -MD -MQ main.p/main.c.o -MF main.p/main.c.o.d -o main.p/main.c.o -c ../../../testmesonstaticlink/main.c
[3/4] rm -f libs2.a && gcc-ar csrD libs2.a libs2.a.p/s2.c.o
[4/4] cc -o main main.p/main.c.o -Wl,--as-needed -Wl,--no-undefined '-Wl,-rpath,$ORIGIN/' -Wl,-rpath-link,/home/woju/src/meson/build-test/ -Wl,--start-group libs2.a -Wl,--end-group
FAILED: main
cc -o main main.p/main.c.o -Wl,--as-needed -Wl,--no-undefined '-Wl,-rpath,$ORIGIN/' -Wl,-rpath-link,/home/woju/src/meson/build-test/ -Wl,--start-group libs2.a -Wl,--end-group
/usr/bin/ld: libs2.a(s2.c.o): in function `s2':
/home/woju/src/meson/build-test/../../../testmesonstaticlink/s2.c:5: undefined reference to `s1'
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
Difference between ninja.build files:
--- right/build.ninja 2023-07-18 17:40:12.503267754 +0200
+++ wrong/build.ninja 2023-07-18 17:40:04.743527324 +0200
@@ -59,8 +59,8 @@
DEPFILE_UNQUOTED = main.p/main.c.o.d
ARGS = -Imain.p -I. -I../../../testmesonstaticlink -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -O0 -g
-build main: c_LINKER main.p/main.c.o | libs1.a libs2.a
- LINK_ARGS = -Wl,--as-needed -Wl,--no-undefined '-Wl,-rpath,$$ORIGIN/' -Wl,-rpath-link,/home/woju/src/meson/build-test/ -Wl,--start-group libs2.a libs1.a -Wl,--end-group
+build main: c_LINKER main.p/main.c.o | libs2.a
+ LINK_ARGS = -Wl,--as-needed -Wl,--no-undefined '-Wl,-rpath,$$ORIGIN/' -Wl,-rpath-link,/home/woju/src/meson/build-test/ -Wl,--start-group libs2.a -Wl,--end-group
# Test rules
acknowledgement
Originally reported by @anjalirai-intel as gramineproject/gramine#1459
Activity
xclaesse commentedon Jul 18, 2023
The expected behaviour is a setup time error. s2 is installed but not s1, that means s2 must contain object files from s1 which Meson cannot currently do. It would have to extract the archive, similar to what that PR wants to achieve: #9218.
Fix error cases when a static library is built as custom target
Fix error cases when a static library is built as custom target
Error when an installed static library links to internal custom target
Error when an installed static library links to internal custom target
Error when an installed static library links to internal custom target
Error when an installed static library links to internal custom target
Error when an installed static library links to internal custom target
Error when an installed static library links to internal custom target
Error when an installed static library links to internal custom target
Error when an installed static library links to internal custom target
Error when an installed static library links to internal custom target
Error when an installed static library links to internal custom target
Error when an installed static library links to internal custom target