title: Undefined reference CUDA and CMAKE
body: <p>I am trying to build a small tool that works with make but I want to create a cmake file for future stuff. I can't figure out what the issue is with the linking.</p>
  
  <pre><code>cmake_minimum_required(VERSION 3.0)
  
  PROJECT(vis_3d)
  
  #find_package(VTK REQUIRED)
  find_package(CUDA REQUIRED)
  find_package(GLEW REQUIRED )
  find_package(GLUT)
  find_package(OpenGL REQUIRED)
  
  set(CUDA_SEPARABLE_COMPILATION ON)
  set(CUDA_PROPAGATE_HOST_FLAGS OFF)
  
  set(SOURCE main.cpp )
  set(HEADERS interactions.h )
  
  set(KERNEL_S kernel.cu device_funcs.cu )
  set(KERNEL_h kernel.h device_funcs.cuh )
  
  include_directories(${vis_3d_SOURCE_DIR})
  
  include_directories(${CUDA_INCLUDE_DIRS}
                      ${OPENGL_INCLUDE_DIRS} 
                      ${GLUT_INCLUDE_DIRS}
                      $(GLEW_INCLUDE_DIRS)
                      /usr/local/cuda/samples/common/inc
                      )
  
  CUDA_ADD_LIBRARY(device_funcs device_funcs.cu)
  target_link_libraries(device_funcs ${CUDA_LIBRARIES})
  
  CUDA_ADD_LIBRARY(kernel_device kernel.cu device_funcs.cu )
  target_link_libraries(kernel_device ${CUDA_LIBRARIES})
  
  include_directories(${kernel_device} ${device_funcs})
  
  cuda_add_executable(vis_3d 
          ${SOURCE} ${HEADERS}
          ${KERNEL_h}
          ) 
  
  #include_directories(${kernel_device} ${device_funcs})
  target_link_libraries(vis_3d
          #${VTK_LIBRARIES}
          ${kernel_device} ${device_funcs}
          ${CUDA_LIBRARIES} ${OPENGL_LIBRARIES} ${GLUT_LIBRARY}
          ${GLEW_LIBRARIES} -lglut -lGL -lGLU -lGLEW
          )
  </code></pre>
  
  <p>error</p>
  
  <blockquote>
    <p>[ 90%] Linking CXX executable vis_3d
        CMakeFiles/vis_3d.dir/main.cpp.o: In function <code>mymenu(int)':
        main.cpp:(.text+0x8b): undefined reference to</code>volumeKernelLauncher(float*, int3, int, float4)'
        CMakeFiles/vis_3d.dir/main.cpp.o: In function <code>render()':
        main.cpp:(.text+0x385): undefined reference to</code>kernelLauncher(uchar4*, float*, int, int, int3, int, int, float,
    float, float)'
        CMakeFiles/vis_3d.dir/main.cpp.o: In function <code>main':
        main.cpp:(.text+0x699): undefined reference to</code>volumeKernelLauncher(float*, int3, int, float4)'
        collect2: error: ld returned 1 exit status
        make[2]: <strong>* [vis_3d] Error 1
        make[1]: *</strong> [CMakeFiles/vis_3d.dir/all] Error 2
        make: *** [all] Error 2</p>
  </blockquote>
  
  <p>make file</p>
  
  <pre><code>UNAME_S := $(shell uname)
  ifeq ($(UNAME_S), Darwin)
      LDFLAGS = -Xlinker -framework,OpenGL -Xlinker -framework,GLUT
  else
      LDFLAGS += -L/usr/local/cuda/samples/common/lib/linux/x86_64
      LDFLAGS += -lglut -lGL -lGLU -lGLEW
  endif
  
  NVCC = /usr/local/cuda/bin/nvcc
  NVCC_FLAGS=-Xcompiler "-Wall -Wno-deprecated-declarations" -rdc=true
  INC = -I/usr/local/cuda/samples/common/inc
  all: main.exe
  main.exe: main.o kernel.o device_funcs.o
      $(NVCC) $^ -o $@ $(LDFLAGS)
  main.o: main.cpp kernel.h interactions.h
      $(NVCC) $(NVCC_FLAGS) -c $&lt; -o $@
  kernel.o: kernel.cu kernel.h device_funcs.cuh
      $(NVCC) $(NVCC_FLAGS) $(INC) -c $&lt; -o $@
  device_funcs.o: device_funcs.cu device_funcs.cuh
      $(NVCC) $(NVCC_FLAGS) $(INC) -c $&lt; -o $@
  clean:
      rm -f *.o *.exe
  </code></pre>