I have a project that requires some dependencies compiled with GCC 9.2.0. The project also depends on CUDA, as I have some kernels. I am using CMake in Linux. For the project itself, I am also compiling with GCC 9.2.0
If I only specify project(MyProject CXX CUDA)
and compile it with no kernels, everything works fine, and the linking line is the following:
[100%] Linking CXX executable PerformanceTest
cd /home/jjcasmar/projects/Tests/Eigen/build/Release/PerformanceTest && /usr/bin/cmake -E cmake_link_script CMakeFiles/PerformanceTest.dir/link.txt --verbose=1
/usr/bin/c++ -O3 -DNDEBUG CMakeFiles/PerformanceTest.dir/TestPerformance.cpp.o -o PerformanceTest /usr/local/lib/libbenchmark.a -lmkl_intel_lp64 -lmkl_sequential -lmkl_core -lm /usr/lib/libdl.so -lpthread /usr/lib/librt.so
If I add a .cu file to the project, then CMake changes the linking line and the project fail to link
[100%] Linking CXX executable PerformanceTest
cd /home/jjcasmar/projects/Tests/Eigen/build/Release/PerformanceTest && /usr/bin/cmake -E cmake_link_script CMakeFiles/PerformanceTest.dir/link.txt --verbose=1
/usr/bin/c++ -O3 -DNDEBUG CMakeFiles/PerformanceTest.dir/TestPerformance.cpp.o CMakeFiles/PerformanceTest.dir/a.cu.o -o PerformanceTest -L/opt/cuda/targets/x86_64-linux/lib/stubs -L/opt/cuda/targets/x86_64-linux/lib -L/usr/lib/gcc/x86_64-pc-linux-gnu/8.3.0 /usr/local/lib/libbenchmark.a -lmkl_intel_lp64 -lmkl_sequential -lmkl_core -lm /usr/lib/libdl.so -lpthread /usr/lib/librt.so -lcudadevrt -lcudart_static -lrt -lpthread -ldl
/usr/bin/ld: /usr/local/lib/libbenchmark.a(benchmark_register.cc.o): in function `nlohmann::detail::serializer<nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer> >::throw_if_invalid_utf8(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
benchmark_register.cc:(.text._ZN8nlohmann6detail10serializerINS_10basic_jsonISt3mapSt6vectorNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEblmdSaNS_14adl_serializerEEEE21throw_if_invalid_utf8ERKSA_[_ZN8nlohmann6detail10serializerINS_10basic_jsonISt3mapSt6vectorNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEblmdSaNS_14adl_serializerEEEE21throw_if_invalid_utf8ERKSA_]+0x42c): undefined reference to `std::__cxx11::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >::basic_stringstream()'
collect2: error: ld returned 1 exit status
The difference is that when I add a .cu file which is compiled with nvcc, the linking line contains -L/usr/lib/gcc/x86_64-pc-linux-gnu/8.3.0
.
Is there any way to fix this?