1

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.

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
        )

error

[ 90%] Linking CXX executable vis_3d CMakeFiles/vis_3d.dir/main.cpp.o: In function mymenu(int)': main.cpp:(.text+0x8b): undefined reference tovolumeKernelLauncher(float*, int3, int, float4)' CMakeFiles/vis_3d.dir/main.cpp.o: In function render()': main.cpp:(.text+0x385): undefined reference tokernelLauncher(uchar4*, float*, int, int, int3, int, int, float, float, float)' CMakeFiles/vis_3d.dir/main.cpp.o: In function main': main.cpp:(.text+0x699): undefined reference tovolumeKernelLauncher(float*, int3, int, float4)' collect2: error: ld returned 1 exit status make[2]: * [vis_3d] Error 1 make[1]: * [CMakeFiles/vis_3d.dir/all] Error 2 make: *** [all] Error 2

make file

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 $< -o $@
kernel.o: kernel.cu kernel.h device_funcs.cuh
    $(NVCC) $(NVCC_FLAGS) $(INC) -c $< -o $@
device_funcs.o: device_funcs.cu device_funcs.cuh
    $(NVCC) $(NVCC_FLAGS) $(INC) -c $< -o $@
clean:
    rm -f *.o *.exe
  • 1
    You don't need `${...}` for `kernel_device` and `device_funcs`. Just use them directly like this: `target_link_libraries(vis_3d kernel_device device_funcs ...` – Pavan Yalamanchili Mar 17 '16 at 22:14

1 Answers1

1

Not really a solution, but this is due to a bug in FindCUDA (cmake library for cuda). It doesn't really work with separable compilation. All definitions of cuda functions are lost in the extra link phase.

See here: https://cmake.org/Bug/view.php?id=15157 and https://stackoverflow.com/a/33233086/2702753

Community
  • 1
  • 1
kalj
  • 1,432
  • 2
  • 13
  • 30