CMake does not link doctest to std library



  • The project is being developed under Windows and Ubuntu. It uses CMake and CLang on Linux. I can build and run from a shell script but it fails to compile using Qt 5.14.0 (QT Creator 4.11.0).

    Some of the captured output:

    [8/9 4.4/sec] Linking CXX executable test/test_runner
    FAILED: : && /opt/clang+llvm-9.0.0-x86_64-linux-gnu-ubuntu-16.04/bin/clang-9  -g -O0 -Wall -pthread --verbose   test/CMakeFiles/test_runner.dir/test_runner.cpp.o test/CMakeFiles/test_runner.dir/test.cpp.o  -o test/test_runner  PSCOM_LIB.a && :
    clang version 9.0.0 (https://github.com/llvm-mirror/llvm c62b24f070c9a4bb1a76409e623042a740cac4cd)
    Target: x86_64-unknown-linux-gnu
    Thread model: posix
    InstalledDir: /opt/clang+llvm-9.0.0-x86_64-linux-gnu-ubuntu-16.04/bin
    ...
     "/usr/bin/ld" -z relro --hash-style=gnu --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o test/test_runner /usr/lib/gcc/x86_64-linux-gnu/7.4.0/../../../x86_64-linux-gnu/crt1.o /usr/lib/gcc/x86_64-linux-gnu/7.4.0/../../../x86_64-linux-gnu/crti.o /usr/lib/gcc/x86_64-linux-gnu/7.4.0/crtbegin.o -L/usr/lib/gcc/x86_64-linux-gnu/7.4.0 -L/usr/lib/gcc/x86_64-linux-gnu/7.4.0/../../../x86_64-linux-gnu -L/lib/x86_64-linux-gnu -L/lib/../lib64 -L/usr/lib/x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/7.4.0/../../.. -L/opt/clang+llvm-9.0.0-x86_64-linux-gnu-ubuntu-16.04/bin/../lib -L/lib -L/usr/lib test/CMakeFiles/test_runner.dir/test_runner.cpp.o test/CMakeFiles/test_runner.dir/test.cpp.o PSCOM_LIB.a -lgcc --as-needed -lgcc_s --no-as-needed -lpthread -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/gcc/x86_64-linux-gnu/7.4.0/crtend.o /usr/lib/gcc/x86_64-linux-gnu/7.4.0/../../../x86_64-linux-gnu/crtn.o
    test/CMakeFiles/test_runner.dir/test_runner.cpp.o: In function `doctest::detail::rawMemoryToString(void const*, unsigned int)':
    /home/paradigm/dev/source/vcpkg_pml/vcpkg/installed/x64-linux/include/doctest/doctest.h:2853: undefined reference to `std::__cxx11::basic_ostringstream<char, std::char_traits<char>, std::allocator<char> >::basic_ostringstream(std::_Ios_Openmode)'
    /home/paradigm/dev/source/vcpkg_pml/vcpkg/installed/x64-linux/include/doctest/doctest.h:2854: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
    

    There are over 1220 similar errors from doctest. My script produces out that includes this:

    "/usr/bin/ld" ... -lstdc++ -lm -lgcc_s -lgcc -lpthread -lc -lgcc_s -lgcc ...
    

    Is there an obvious to add to my CMakeLists.txt file to make it include the std library?


Log in to reply