<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div>Hi cmake team,</div><div>I'm using cmake 3.12.1, and building a project which has cuda codes, the cmake file looks like,</div><div><div>list(APPEND ALL_OBJECTS  $<TARGET_OBJECTS: normal_obj>)</div></div><div>

<span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">list(APPEND ALL_OBJECTS  $<TARGET_OBJECTS: cuda_obj>)</span>

<br></div><div>add_library(lib1 SHARED ${ALL_OBJECTS})<br></div><div><div>list(APPEND ALL_LIBRARIES -Wl,-start-group)</div></div><div>

<span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><span>

<span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">list(APPEND ALL_LIBRARIES<span> </span></span> </span>${SOME_LIBS})</span><br></div><div><div>list(APPEND ALL_LIBRARIES -Wl,-end-group)</div></div><div>target_link_libraries(lib1 ${ALL_LIBRARIES})<br></div><div dir="ltr"><br></div><div>Now for this project, cmake will generate a <span style="color:rgb(0,0,0);white-space:pre-wrap">cmake_device_link.o, using the link flags in lib1, then I got error</span></div><div>nvcc 

<span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"> fatal   : Unknown option 'Wl,-start-group'</span>

</div><div><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><br></span></div><div><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">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.</span></div><div><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><br></span></div><div>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::<span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">WriteSharedLibraryRules, and my build can success w/o 

<span style="text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">cmake_device_link.o</span>, so maybe this is also a way to fix the issue.</span></div><div><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><br></span></div><div>I'm new to cmake, so if there's any better way to solve my problem, please let me know.</div><div><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><br></span></div><div><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">Thanks.</span></div><div><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">Alvin</span></div></div></div></div></div></div></div></div></div></div>