[vtk-developers] How to write CMakeLists.txt for a library using CUDA?

Mingcheng Chen linyufly at gmail.com
Mon Mar 17 23:01:03 EDT 2014


Hi Kenneth,

Thanks a lot!

Best regards,
Mingcheng Chen
March 17th, 2014


On Mon, Mar 17, 2014 at 4:32 PM, Moreland, Kenneth <kmorel at sandia.gov>wrote:

>   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.
>
>  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:
> http://stackoverflow.com/questions/5856929/configuring-cmake-to-setup-cuda-on-windows
>
>  -Ken
>
>   From: Mingcheng Chen <linyufly at gmail.com>
> Date: Monday, March 17, 2014 3:21 PM
> To: Kenneth Moreland <kmorel at sandia.gov>
> Cc: "vtk-developers at vtk.org" <vtk-developers at vtk.org>, vtkusers <
> vtkusers-bounces at vtk.org>
> Subject: [EXTERNAL] Re: [vtk-developers] How to write CMakeLists.txt for
> a library using CUDA?
>
>     Hi Kenneth,
>
>  Thanks a lot for your advice!
>
>  I followed your advice and successfully built *.so and *.a for the same
> library, and my following code can use *.so library successfully!
>
> I have two follower questions:
>  (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?
>
>  (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?
>
> Thanks again!
>
> Best regards,
> Mingcheng Chen
>  March 17th, 2014
>
>
> On Mon, Mar 17, 2014 at 12:59 PM, Moreland, Kenneth <kmorel at sandia.gov>wrote:
>
>>   This question is really more applicable to the VTK users list, so I'm
>> responding to there as well.
>>
>>  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.
>>
>>  For more information, try this command prompt command: "cmake
>> --help-module FindCUDA | less". You can also find several examples on the
>> web.
>>
>>  -Ken
>>
>>   From: Mingcheng Chen <linyufly at gmail.com>
>> Date: Sunday, March 16, 2014 11:36 AM
>> To: "vtk-developers at vtk.org" <vtk-developers at vtk.org>
>> Subject: [EXTERNAL] [vtk-developers] How to write CMakeLists.txt for a
>> library using CUDA?
>>
>>   Hi everyone,
>>
>>  Thanks for your time!
>>
>>  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?
>>
>>  Thanks!
>>
>>  Best regards,
>> Mingcheng Chen
>> March 16th, 2014
>>
>>  --
>>  Research Assistant in Graphics Group
>>  University of Illinois at Urbana-Champaign
>> http://mingchengchen.org
>>
>
>
>
> --
>  Research Assistant in Graphics Group
>  University of Illinois at Urbana-Champaign
> http://mingchengchen.org
>



-- 
Research Assistant in Graphics Group
University of Illinois at Urbana-Champaign
http://mingchengchen.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtk-developers/attachments/20140317/9c967ce8/attachment-0002.html>


More information about the vtk-developers mailing list