In the meanwhile, I could figure out what is the problem.
To mention also: its a Linux
CMake build.
I had instead of this
- A
set(MY_STATIC_LIB_NAME myStaticLib)
used this
- B
set(MY_STATIC_LIB_NAME libmyStaticLib.a)
The call below (target_link_libraries) functions with both variants.
target_link_libraries(${EXE_NAME} PUBLIC ${MY_STATIC_LIB_NAME})
But the build behaves differently:
- A. Everything works fine, i.e. the lib is build in parallel, and the linker is called after its been built.
- B. CMake didn’t make a connection between
libmyStaticLib.a
andmyStaticLib
from theadd_subdirectory
call. Thus the two were build separately. The linker stripped though the libmyStaticLib.a to myStaticLib and issued an error (/usr/bin/ld: cannot find -lmyStaticLib
) of not finding the library.
Two final questions
- Is the above CMake behavior a bug or a feature ?
- How does CMake internally handles build dependencies, so that it wont call the linker before everything is build, i.e. how is build order handled?