Faulty binary when linking with object libraries depending on Make/Ninja
source
+-- *.cpp, *.hpp
tests
+-- *.cpp
add_library(project_objects OBJECT ${object_files})
target_include_directories(project_objectes ...)
target_link_libraries(project_objects ...)
add_executable(project main.cpp)
target_link_libraries(project project_objects)
add_executable(gtests ${test_files})
target_link_libraries(gtests gtest project_objects)
My default build tool is Ninja; this has worked fine. However, when using Make the test binary sigsegvs on static initialization according to gdb. This only happens with the test executable, not the project executable.
I did a verbose build on both; and it seems like Make does not link the project objects to the gtest executable.
Shortened Ninja output:
ccache /usr/bin/c++ src/CMakeFiles/project_objects.dir/File.cpp.o tests/CMakeFiles/gtests.dir/FileTest.cpp.o <omitted...> -o gtests -lgcov -lgtest
Shortened Make output:
ccache /usr/bin/c++ @CMakeFiles/gtests.dir/objects1.rsp -o gtests -lgcov -lgtest
If I take the command from the Ninja output to link and use it on the Make build, it works correctly.
CMake version: 3.17.3
GCC version: 4.8.5
Ninja version: 1.10.0
Make version: 3.82
Edited by Zain