gpt4 book ai didi

c++ - undefined reference CUDA 和 CMAKE

转载 作者:行者123 更新时间:2023-11-30 05:30:18 25 4
gpt4 key购买 nike

我正在尝试构建一个与 make 一起使用的小工具,但我想为将来的东西创建一个 cmake 文件。我不知道链接有什么问题。

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
)

错误

[ 90%] Linking CXX executable vis_3d CMakeFiles/vis_3d.dir/main.cpp.o: In function mymenu(int)':
main.cpp:(.text+0x8b): undefined reference to
volumeKernelLauncher(float*, int3, int, float4)' CMakeFiles/vis_3d.dir/main.cpp.o: In function render()':
main.cpp:(.text+0x385): undefined reference to
kernelLauncher(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 to
volumeKernelLauncher(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

制作文件

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

最佳答案

不是真正的解决方案,但这是由于 FindCUDA(cuda 的 cmake 库)中的一个错误。它不适用于可分离的编译。 cuda 函数的所有定义都在额外链接阶段丢失。

参见此处:https://cmake.org/Bug/view.php?id=15157https://stackoverflow.com/a/33233086/2702753

关于c++ - undefined reference CUDA 和 CMAKE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36018726/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com