<div dir="ltr">Thank you Marc, here we have to put "

<span style="color:rgb(80,0,80)">-Wl,-start-group" and "</span>

<span style="color:rgb(80,0,80)"> -Wl,-end-group" in </span>

<span style="color:rgb(80,0,80)">target_link_libraries because these two link flags are special, must used between link targets.</span><div><font color="#500050">Now my way to fix is to use "-Xlinker -start-group" and "-Xlinker -end-group" instead. <br></font><div><font color="#500050"><br></font><div><br></div><div>Thanks.</div><div>Alvin</div></div></div></div><br><div class="gmail_quote"><div dir="ltr">On Fri, Sep 7, 2018 at 11:45 PM Marc CHEVRIER <<a href="mailto:marc.chevrier@gmail.com">marc.chevrier@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br><br>To avoid this, put link flags in ‘LINK_FLAGS’ target properly.<br>´target_link_libraries’ is populating ´LINK_LIBRARIES’ target property.<br><br><div class="gmail_quote"><div dir="ltr">Le sam. 8 sept. 2018 à 01:40, Alvin Chu <<a href="mailto:chujingjun@gmail.com" target="_blank">chujingjun@gmail.com</a>> a écrit :<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><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>
-- <br>
<br>
Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a><br>
<br>
Please keep messages on-topic and check the CMake FAQ at: <a href="http://www.cmake.org/Wiki/CMake_FAQ" rel="noreferrer" target="_blank">http://www.cmake.org/Wiki/CMake_FAQ</a><br>
<br>
Kitware offers various services to support the CMake community. For more information on each offering, please visit:<br>
<br>
CMake Support: <a href="http://cmake.org/cmake/help/support.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/support.html</a><br>
CMake Consulting: <a href="http://cmake.org/cmake/help/consulting.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/consulting.html</a><br>
CMake Training Courses: <a href="http://cmake.org/cmake/help/training.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/training.html</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="https://cmake.org/mailman/listinfo/cmake" rel="noreferrer" target="_blank">https://cmake.org/mailman/listinfo/cmake</a><br>
</blockquote></div>
</blockquote></div>