I am currently working on a project that uses the bonding capabilities of Cuda 5 objects. As the project begins to get complex, I wanted to switch to using cmake to compile the code. However, I cannot get the object to attach to work correctly for me.
In the end, I created a toy version of the project that gets the same errors as the original project. The toy project consists of the main file (TextureMain.cu), which calls the kernel function to work on the GPU. In each GPU thread, an instance of a custom class (TextureFunc) is indicated, where the class exists in a separate folder from the main file. The class consists of the TextureFunc.cu and TextureFunc.h files in this folder.
Here are the CMakeList.txt files that I use:
In the project directory (contains the src directory):
project(TextureMain)
cmake_minimum_required(VERSION 2.8)
find_package(CUDA REQUIRED)
set(CUDA_NVCC_FLAGS "-arch=compute_20; -code=sm_20; -rdc=true; -lcudadevrt")
include_directories(src/TextureFunc)
add_subdirectory(src/TextureFunc)
add_subdirectory(src)
In the src directory (contains the TextureMain.cu and TextureFunc directory):
cuda_add_executable(TextureMain TextureMain.cu)
target_link_libraries(TextureMain TextureFunc)
install(TARGETS TextureMain DESTINATION bin)
In the TextureFunc directory (contains TextureFunc.h and TextureFunc.cu):
cuda_add_library(TextureFunc TextureFunc.cu )
target_link_libraries(TextureFunc)
When I try to compile this code using the above CMakeList.txt files, I get the following error.
Linking CXX executable TextureMain
CMakeFiles/TextureMain.dir/./TextureMain_generated_TextureMain.cu.o: In function `__sti____cudaRegisterAll_46_tmpxft_00004c15_00000000_6_TextureMain_cpp1_ii_texRef':
/tmp/tmpxft_00004c15_00000000-3_TextureMain.cudafe1.stub.c:2: undefined reference to `__cudaRegisterLinkedBinary_46_tmpxft_00004c15_00000000_6_TextureMain_cpp1_ii_texRef'
TextureFunc/libTextureFunc.a(TextureFunc_generated_TextureFunc.cu.o): In function `__sti____cudaRegisterAll_46_tmpxft_00004bd8_00000000_6_TextureFunc_cpp1_ii_421ca072':
/tmp/tmpxft_00004bd8_00000000-3_TextureFunc.cudafe1.stub.c:8: undefined reference to `__cudaRegisterLinkedBinary_46_tmpxft_00004bd8_00000000_6_TextureFunc_cpp1_ii_421ca072'
collect2: ld returned 1 exit status
make[2]: *** [src/TextureMain] Error 1
make[1]: *** [src/CMakeFiles/TextureMain.dir/all] Error 2
This is obviously a binding error, and it is probably due to the way I compile the code with cmake. I think the flags for nvcc are correct, since I was able to compile this project using the Makefile with the same flags. However, I'm not quite sure what else I can do wrong. I noticed that the error message refers to some non-existent .cpp files, but I do not know what to do with it.
Any advice that could be given would be greatly appreciated. I am using cmake version 2.8.8.