[CMake] [CMAKE] cmake_device_link.o: nvcc fatal: Unknown option 'Wl, -start-group'

Alvin Chu chujingjun at gmail.com
Fri Sep 7 19:39:28 EDT 2018


Hi cmake team,
I'm using cmake 3.12.1, and building a project which has cuda codes, the
cmake file looks like,
list(APPEND ALL_OBJECTS  $<TARGET_OBJECTS: normal_obj>)
list(APPEND ALL_OBJECTS  $<TARGET_OBJECTS: cuda_obj>)
add_library(lib1 SHARED ${ALL_OBJECTS})
list(APPEND ALL_LIBRARIES -Wl,-start-group)
list(APPEND ALL_LIBRARIES  ${SOME_LIBS})
list(APPEND ALL_LIBRARIES -Wl,-end-group)
target_link_libraries(lib1 ${ALL_LIBRARIES})

Now for this project, cmake will generate a cmake_device_link.o, using the
link flags in lib1, then I got error
nvcc   fatal   : Unknown option 'Wl,-start-group'

I checked cmake source code, and seems cmake doesn't check if the link
flags in lib1 is supported by nvcc or not, and it directly passed all the
flag to nvcc which caused the problem. Maybe this is one way to fix this
issue.

I also noticed cmMakefileLibraryTargetGenerator::WriteStaticLibraryRules
will check CUDA_RESOLVE_DEVICE_SYMBOLS to decide if need generate
cmake_device_link.o or not,
but cmMakefileLibraryTargetGenerator::WriteSharedLibraryRules don't, I
tried add this check in
cmMakefileLibraryTargetGenerator::WriteSharedLibraryRules,
and my build can success w/o cmake_device_link.o, so maybe this is also a
way to fix the issue.

I'm new to cmake, so if there's any better way to solve my problem, please
let me know.

Thanks.
Alvin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake/attachments/20180907/83752983/attachment.html>


More information about the CMake mailing list