Le 12/02/2025 à 05:57, Simon Richter a écrit :
Hi,
On 2/12/25 13:38, Johannes Schauer Marin Rodrigues wrote:
["DSO missing from command line"]
I suspect that the problem is the order in which the -latomic is added to the
linker flags?
Yes.
Because if instead of target_link_options() with push and
pop-state I just use
target_link_libraries(vcmiclient PRIVATE atomic)
Then that will add a -latomic right after ../bin/libvcmiclientcommon.a and then
the build succeeds.
Yes, that is the correct approach -- that target is dependent on libatomic.
You can combine both: just put the previous options in the linker libraries
instead of linker options:
$ cat ../CMakeLists.txt
cmake_minimum_required(VERSION 3.25)
project (LinkTest)
ADD_EXECUTABLE(prog prog.c)
target_link_libraries(prog "-Wl,--push-state,--as-needed,-latomic,--pop-state")
$ cmake ..
[...]
$ make VERBOSE=1
[...]
/usr/bin/cc -Wl,--dependency-file=CMakeFiles/prog.dir/link.d
CMakeFiles/prog.dir/prog.c.o -o prog
-Wl,--push-state,--as-needed,-latomic,--pop-state
[...]
Using target_link_libraries() instead of target_link_options() puts the text
after the linked object files (instead of before).
The order is important (libraries are used to resolve missing symbols of
*previous* libraries/object files).
Be sure to declare your target_link_libraries() after adding all object
files/libraries that might need it.
For autoconf, it means putting it in LIBS (and not LDFLAGS)
Regards,
Vincent