CUDArt link order regression with 3.22.0
With the upgrade from 3.21.3 to 3.22.0, the static build of a library depending on CUDA symbols does not work anymore. It fails with:
/home/fberchtold/.conan/data/lum_platform_system_gpu/1.0.0/_/_/package/305be889d357f53551516450d8abe1ab5b425f1e/lib/liblum_platform_system_gpu.a(gpu_nvidia.cpp.o): In function `lum::platform::system::gpu::nvidia::GpuDataManager::getGpuMemory()':
gpu_nvidia.cpp:(.text+0x1d8): undefined reference to `cudaGetDeviceCount'
gpu_nvidia.cpp:(.text+0x1fe): undefined reference to `cudaSetDevice'
gpu_nvidia.cpp:(.text+0x209): undefined reference to `cudaMemGetInfo'
Relevant CMake:
enable_language(CUDA)
find_package(CUDAToolkit REQUIRED)
add_library(lum_platform_system_gpu src/gpu_nvidia.cpp)
target_include_directories(lum_platform_system_gpu PUBLIC include)
target_link_libraries(lum_platform_system_gpu PUBLIC CUDA::cudart)
add_executable(gpu_test gpu_nvidia_test.cpp)
target_link_libraries(gpu_test PRIVATE lum_platform_system_gpu)
I found out that one of the differences between the two versions is the link order in link.txt
:
-
3.21.3 - working
:/usr/local/cuda/lib64/libcudart.so
is last to be linked -
3.22.0 - fails
:/usr/local/cuda/lib64/libcudart.so
is linked before the library using its symbols
FYI: shared builds of the library still seem to work.