<div dir="ltr">Hi Kenneth,<br><br>Thanks a lot!<br><br>Best regards,<br>Mingcheng Chen<br>March 17th, 2014<br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Mar 17, 2014 at 4:32 PM, Moreland, Kenneth <span dir="ltr"><<a href="mailto:kmorel@sandia.gov" target="_blank">kmorel@sandia.gov</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">



<div style="font-size:14px;font-family:Calibri,sans-serif;word-wrap:break-word">
<div>
<div>
<div>I don't know if I understand your first question, but you should always specify all the libraries that any target depends on with target_link_libraries. I think you are getting away with not specifying the shared object because the linker is picking up
 the .so in your LD_LIBRARY_PATH, but in general you should not assume that will work.</div>
</div>
</div>
<div><br>
</div>
<div>For the second question, I don't have experience with Visual Studio, but a quick Google search came up with this page that seems to answer the same question: <a href="http://stackoverflow.com/questions/5856929/configuring-cmake-to-setup-cuda-on-windows" target="_blank">http://stackoverflow.com/questions/5856929/configuring-cmake-to-setup-cuda-on-windows</a></div>

<div><br>
</div>
<div>-Ken</div>
<div><br>
</div>
<span>
<div style="border-right:medium none;padding-right:0in;padding-left:0in;padding-top:3pt;text-align:left;font-size:11pt;border-bottom:medium none;font-family:Calibri;border-top:#b5c4df 1pt solid;padding-bottom:0in;border-left:medium none">

<span style="font-weight:bold">From: </span>Mingcheng Chen <<a href="mailto:linyufly@gmail.com" target="_blank">linyufly@gmail.com</a>><br>
<span style="font-weight:bold">Date: </span>Monday, March 17, 2014 3:21 PM<br>
<span style="font-weight:bold">To: </span>Kenneth Moreland <<a href="mailto:kmorel@sandia.gov" target="_blank">kmorel@sandia.gov</a>><br>
<span style="font-weight:bold">Cc: </span>"<a href="mailto:vtk-developers@vtk.org" target="_blank">vtk-developers@vtk.org</a>" <<a href="mailto:vtk-developers@vtk.org" target="_blank">vtk-developers@vtk.org</a>>, vtkusers <<a href="mailto:vtkusers-bounces@vtk.org" target="_blank">vtkusers-bounces@vtk.org</a>><br>

<span style="font-weight:bold">Subject: </span>[EXTERNAL] Re: [vtk-developers] How to write CMakeLists.txt for a library using CUDA?<br>
</div><div><div class="h5">
<div><br>
</div>
<div>
<div>
<div dir="ltr">
<div>
<div>
<div>
<div>
<div>Hi Kenneth,<br>
<br>
</div>
Thanks a lot for your advice!<br>
<br>
</div>
I followed your advice and successfully built *.so and *.a for the same library, and my following code can use *.so library successfully!<br>
<br>
I have two follower questions:<br>
</div>
(1) I have link error if I want to compile something using my *.a library, but the CMakeLists.txt is almost the same as the one using *.so library. I use target_link_libraries(myApp ${VTK_SOURCE_DIR}/myLib.a) and target_link_libraries(myApp ${VTK_SOURCE_DIR}/myLib.so)
 for both. Is there anything I should consider for *.a library?<br>
<br>
</div>
(2) The CMakeLists.txt that works in Ubuntu does not work in Visual Studio. The *.sln it creates is not a CUDA project. How to solve that problem?<br>
<br>
Thanks again!<br>
<br>
Best regards,<br>
Mingcheng Chen<br>
</div>
March 17th, 2014<br>
</div>
<div class="gmail_extra"><br>
<br>
<div class="gmail_quote">On Mon, Mar 17, 2014 at 12:59 PM, Moreland, Kenneth <span dir="ltr">
<<a href="mailto:kmorel@sandia.gov" target="_blank">kmorel@sandia.gov</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div style="font-size:14px;font-family:Calibri,sans-serif;word-wrap:break-word">
<div>
<div>
<div>This question is really more applicable to the VTK users list, so I'm responding to there as well.</div>
</div>
</div>
<div><br>
</div>
<div>The short answer is that if you add the command "find_package(CUDA REQUIRED)" to your CMakeLists.txt, that will load the CMake code to find the CUDA install. Then you replace add_library with cuda_add_library. You also have to use a .cu extension for your
 C or C++ files that use CUDA instead of .c or .cxx or .cpp. The cuda_add_library will only use the requisite nvcc compiler on files with a .cu extension.</div>
<div><br>
</div>
<div>For more information, try this command prompt command: "cmake --help-module FindCUDA | less". You can also find several examples on the web.</div>
<div><br>
</div>
<div>-Ken</div>
<div><br>
</div>
<span>
<div style="border-right:medium none;padding-right:0in;padding-left:0in;padding-top:3pt;text-align:left;font-size:11pt;border-bottom:medium none;font-family:Calibri;border-top:#b5c4df 1pt solid;padding-bottom:0in;border-left:medium none">

<span style="font-weight:bold">From: </span>Mingcheng Chen <<a href="mailto:linyufly@gmail.com" target="_blank">linyufly@gmail.com</a>><br>
<span style="font-weight:bold">Date: </span>Sunday, March 16, 2014 11:36 AM<br>
<span style="font-weight:bold">To: </span>"<a href="mailto:vtk-developers@vtk.org" target="_blank">vtk-developers@vtk.org</a>" <<a href="mailto:vtk-developers@vtk.org" target="_blank">vtk-developers@vtk.org</a>><br>

<span style="font-weight:bold">Subject: </span>[EXTERNAL] [vtk-developers] How to write CMakeLists.txt for a library using CUDA?<br>
</div>
<div>
<div>
<div><br>
</div>
<div>
<div>
<div dir="ltr">Hi everyone,
<div><br>
</div>
<div>Thanks for your time!</div>
<div><br>
</div>
<div>I write a class which uses VTK and CUDA, and I want to write a CMakeLists.txt for others to build my library. I only know how to write CMakeLists.txt for executables. Could anybody please show me how to write for a library?</div>

<div><br>
</div>
<div>Thanks!</div>
<div><br>
</div>
<div>Best regards,</div>
<div>Mingcheng Chen</div>
<div>March 16th, 2014<br clear="all">
<div><br>
</div>
-- <br>
<div dir="ltr">
<div>Research Assistant in Graphics Group<br>
</div>
<div>University of Illinois at Urbana-Champaign</div>
<div><a href="http://mingchengchen.org" target="_blank">http://mingchengchen.org</a></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</span></div>
</blockquote>
</div>
<br>
<br clear="all">
<br>
-- <br>
<div dir="ltr">
<div>Research Assistant in Graphics Group<br>
</div>
<div>University of Illinois at Urbana-Champaign</div>
<div><a href="http://mingchengchen.org" target="_blank">http://mingchengchen.org</a></div>
</div>
</div>
</div>
</div>
</div></div></span>
</div>

</blockquote></div><br><br clear="all"><br>-- <br><div dir="ltr"><div>Research Assistant in Graphics Group<br></div>
<div>University of Illinois at Urbana-Champaign</div><div><a href="http://mingchengchen.org" target="_blank">http://mingchengchen.org</a></div></div>
</div>