Problem when linking a library on a target with CUDA sources

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Problem when linking a library on a target with CUDA sources

victornement
Hello,

I have a project with a few dependencies (Qt, opencv, aravis, etc) and I would like to add some sources in CUDA.

Here is a minimal example:

cmake_minimum_required(VERSION 3.0)
project(myproject CXX CUDA)
find_package(Qt5 REQUIRED COMPONENTS Core)
add_executable(mytarget main.cpp gpu.cu)
target_link_libraries(mytarget PUBLIC Qt5::Core)

The previous example gives the following output

[ 25%] Building CUDA object CMakeFiles/mytarget.dir/gpu.cu.o
nvcc fatal   : Unknown option 'fPIC'
make[2]: *** [CMakeFiles/mytarget.dir/build.make:76: CMakeFiles/mytarget.dir/gpu.cu.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:73: CMakeFiles/mytarget.dir/all] Error 2
make: *** [Makefile:84: all] Error 2

I would get the same problem if I replace target_link_libraries with

set_target_properties(mytarget PROPERTIES COMPILE_OPTIONS -pthread)

Does anyone know why I get this error? Am I doing it rightly? Is it a bug?

Sincerely,

Victor ML
--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: Problem when linking a library on a target with CUDA sources

CMake mailing list
This is caused by a combination of two things:

1. nvcc does not accept standard flags such as fpic or pthread
2. Packages such as Qt or your call to set_target_properties not
handling CUDA/C++ compilers having different flags.

For your pthread example you can use the following ( which is what
FindThreads.cmake does )

    set_target_property((mytarget PROPERTIES COMPILE_OPTIONS

"$<$<COMPILE_LANGUAGE:CUDA>:SHELL:-Xcompiler -pthread>
$<$<NOT:$<COMPILE_LANGUAGE:CUDA>>:-pthread>")

On Thu, Jan 3, 2019 at 1:31 PM <[hidden email]> wrote:

>
> Hello,
>
> I have a project with a few dependencies (Qt, opencv, aravis, etc) and I would like to add some sources in CUDA.
>
> Here is a minimal example:
>
> cmake_minimum_required(VERSION 3.0)
> project(myproject CXX CUDA)
> find_package(Qt5 REQUIRED COMPONENTS Core)
> add_executable(mytarget main.cpp gpu.cu)
> target_link_libraries(mytarget PUBLIC Qt5::Core)
>
> The previous example gives the following output
>
> [ 25%] Building CUDA object CMakeFiles/mytarget.dir/gpu.cu.o
> nvcc fatal   : Unknown option 'fPIC'
> make[2]: *** [CMakeFiles/mytarget.dir/build.make:76: CMakeFiles/mytarget.dir/gpu.cu.o] Error 1
> make[1]: *** [CMakeFiles/Makefile2:73: CMakeFiles/mytarget.dir/all] Error 2
> make: *** [Makefile:84: all] Error 2
>
> I would get the same problem if I replace target_link_libraries with
>
> set_target_properties(mytarget PROPERTIES COMPILE_OPTIONS -pthread)
>
> Does anyone know why I get this error? Am I doing it rightly? Is it a bug?
>
> Sincerely,
>
> Victor ML
> --
>
> Powered by www.kitware.com
>
> Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
>
> Kitware offers various services to support the CMake community. For more information on each offering, please visit:
>
> CMake Support: http://cmake.org/cmake/help/support.html
> CMake Consulting: http://cmake.org/cmake/help/consulting.html
> CMake Training Courses: http://cmake.org/cmake/help/training.html
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Follow this link to subscribe/unsubscribe:
> https://cmake.org/mailman/listinfo/cmake
--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake