I am creating a static library containing some CUDA code and some regular C ++ code. CMakeLists.txt for this static library is as follows:
SET(TARGET_H some_header.h)
SET(CUDA_SRC cudaclass1.cu cudaclass2.cu)
SET(TARGET_SRC cppclass1.cpp cppclass2.cpp)
SET(CUDA_NVCC_FLAGS "")
SET(CUDA_SEPARABLE_COMPILATION ON)
CUDA_ADD_LIBRARY(somestatic ${TARGET_H} ${TARGET_SRC} ${CUDA_SRC} OPTIONS -arch sm_20)
This will lead to the creation of libsomestatic.a.
Now I want to link this static library with an executable file, which itself consists of CUDA code and C ++ code.
In the CUDA code of this executable, I need to instantiate and use CudaClass1 from libsomestatic.a.
This is the CMakeLists.txt file for the executable:
SET(TARGET_H some_header.h)
SET(CUDA_SRC cudafile.cu)
SET(TARGET_SRC main.cpp)
SET(CUDA_NVCC_FLAGS "")
SET(CUDA_SEPARABLE_COMPILATION ON)
CUDA_ADD_EXECUTABLE(some_exe ${TARGET_H} ${TARGET_SRC} ${CUDA_SRC} OPTIONS -arch sm_20)
TARGET_LINK_LIBRARIES(some_exe somestatic)
But when creating, I get the following error:
nvlink error: Undefined reference to '_ZN10test7CudaClass1C1EPKNS_11intE' in ...
I have two questions:
- Is it even possible to do this? Linking CUDA code to a library that contains CUDA code?
- If so, how do I do this with CMake?
CUDA (http://docs.nvidia.com/cuda/cuda-compiler-driver-nvcc/index.html#examples)
" - , ( )"
, , , ?
CUDA 5.5 GCC 4.8.