ubuntu - 在ubuntu中用cuda编译opencv的makefile停止工作

标签 ubuntu opencv makefile cuda

我正在尝试在我的笔记本电脑上编译一个项目,其中我需要 CUDA 和 opencv。
所以我创建了3个文件

主文件

内核.cu

内核.h

在 main.cpp 我有 opencv 代码,在 kernel.cu 我有我的内核。
我正在使用我在另一个项目中找到的这个 makefile:

CXX=g++
CUDA_INSTALL_PATH=/usr/local/cuda
CFLAGS= -I. -I$(CUDA_INSTALL_PATH)/include `pkg-config --cflags opencv`
LDFLAGS= -L$(CUDA_INSTALL_PATH)/lib64 -lcudart `pkg-config --libs opencv`

all:
    $(CXX) $(CFLAGS) -c main.cpp -o main.o
    nvcc $(CUDAFLAGS) -arch="sm_21" -c kernel.cu -o kernel.o
    $(CXX) $(LDFLAGS) main.o kernel.o -o main

我曾在另一台使用 opencv 2.4.2、CUDA 4.0 和 gcc 4.4 的计算机上尝试过相同的项目,它运行良好,但现在我在笔记本电脑上使用 opencv 2.4.2、CUDA 4.2 和 gcc 4.6 进行尝试,它不断返回错误最后一行,但它确实创建了 main.o 和 kernel.o,如果我注释掉最后一行,它不会给出错误。

我已经构建并运行了 opencv 和 cuda sdk 示例,它们分别运行良好。
你能帮助我吗?

这是它返回的内容:

g++ -L/usr/local/cuda/lib64 -lcudart pkg-config --libs opencv main.o kernel_gpu.o -o grayscale

main.o: In function `main':

main.cpp:(.text+0x44): undefined reference to `cv::imread(std::basic_string, std::allocator > const&, int)'

main.cpp:(.text+0x72): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'

main.cpp:(.text+0xa6): undefined reference to `cv::imshow(std::basic_string, std::allocator > const&, cv::_InputArray const&)'

main.cpp:(.text+0xc8): undefined reference to `cv::waitKey(int)'

main.o: In function `cv::Mat::~Mat()':

main.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x39): undefined reference to `cv::fastFree(void*)'

main.o: In function `cv::Mat::release()':

main.cpp:(.text._ZN2cv3Mat7releaseEv[cv::Mat::release()]+0x47): undefined reference to `cv::Mat::deallocate()'

kernel_gpu.o: In function cuda_BGsub': tmpxft_000016bc_00000000-1_kernel_gpu.cudafe1.cpp:(.text+0x41): undefined reference tocudaConfigureCall'

kernel_gpu.o: In function cuda_grayscale': tmpxft_000016bc_00000000-1_kernel_gpu.cudafe1.cpp:(.text+0xb3): undefined reference tocudaConfigureCall'

kernel_gpu.o: In function cuda_Filter': tmpxft_000016bc_00000000-1_kernel_gpu.cudafe1.cpp:(.text+0x10d): undefined reference tocudaConfigureCall'

kernel_gpu.o: In function cuda_Noise_reduc': tmpxft_000016bc_00000000-1_kernel_gpu.cudafe1.cpp:(.text+0x176): undefined reference tocudaConfigureCall'

kernel_gpu.o: In function cuda_RGB': tmpxft_000016bc_00000000-1_kernel_gpu.cudafe1.cpp:(.text+0x1d9): undefined reference tocudaConfigureCall'

kernel_gpu.o:tmpxft_000016bc_00000000-1_kernel_gpu.cudafe1.cpp:(.text+0x234): more undefined references to `cudaConfigureCall' follow

kernel_gpu.o: In function `__cudaUnregisterBinaryUtil()':

tmpxft_000016bc_00000000-1_kernel_gpu.cudafe1.cpp:(.text+0x409): undefined reference to `__cudaUnregisterFatBinary'

kernel_gpu.o: In function `__device_stub__Z5BGsubPhS_S_iib(unsigned char*, unsigned char*, unsigned char*, int, int, bool)':

tmpxft_000016bc_00000000-1_kernel_gpu.cudafe1.cpp:(.text+0x442): undefined reference to `cudaSetupArgument'

tmpxft_000016bc_00000000-1_kernel_gpu.cudafe1.cpp:(.text+0x465): undefined reference to `cudaSetupArgument'

tmpxft_000016bc_00000000-1_kernel_gpu.cudafe1.cpp:(.text+0x488): undefined reference to `cudaSetupArgument'

tmpxft_000016bc_00000000-1_kernel_gpu.cudafe1.cpp:(.text+0x4a7): undefined reference to `cudaSetupArgument'

tmpxft_000016bc_00000000-1_kernel_gpu.cudafe1.cpp:(.text+0x4c6): undefined reference to `cudaSetupArgument'

kernel_gpu.o:tmpxft_000016bc_00000000-1_kernel_gpu.cudafe1.cpp:(.text+0x4e5): more undefined references to `cudaSetupArgument' follow

kernel_gpu.o: In function `sti__cudaRegisterAll_45_tmpxft_000016bc_00000000_4_kernel_gpu_cpp1_ii_cdcbb70e()':

tmpxft_000016bc_00000000-1_kernel_gpu.cudafe1.cpp:(.text+0xe7e): undefined reference to `__cudaRegisterFatBinary'

tmpxft_000016bc_00000000-1_kernel_gpu.cudafe1.cpp:(.text+0xedc): undefined reference to `__cudaRegisterFunction'

tmpxft_000016bc_00000000-1_kernel_gpu.cudafe1.cpp:(.text+0xf29): undefined reference to `__cudaRegisterFunction'

tmpxft_000016bc_00000000-1_kernel_gpu.cudafe1.cpp:(.text+0xf76): undefined reference to `__cudaRegisterFunction'

tmpxft_000016bc_00000000-1_kernel_gpu.cudafe1.cpp:(.text+0xfc3): undefined reference to `__cudaRegisterFunction'

tmpxft_000016bc_00000000-1_kernel_gpu.cudafe1.cpp:(.text+0x1010): undefined reference to `__cudaRegisterFunction'

kernel_gpu.o:tmpxft_000016bc_00000000-1_kernel_gpu.cudafe1.cpp:(.text+0x105d): more undefined references to `__cudaRegisterFunction' follow

kernel_gpu.o: In function `cudaError cudaLaunch(char*)':

tmpxft_000016bc_00000000-1_kernel_gpu.cudafe1.cpp:(.text.Z10cudaLaunchIcE9cudaErrorPT[cudaError cudaLaunch(char*)]+0x14): undefined reference to `cudaLaunch'

collect2: ld returned 1 exit status

make: * [all] Error 1



编辑:
此版本有效:
CXX=g++
CUDA_INSTALL_PATH=/usr/local/cuda
CFLAGS= -I. -I$(CUDA_INSTALL_PATH)/include `pkg-config --cflags opencv`
LDFLAGS= -L$(CUDA_INSTALL_PATH)/lib64 -lcudart `pkg-config --libs opencv`

all:
    $(CXX) $(CFLAGS) -c main.cpp -o main.o
    nvcc $(CUDAFLAGS) -arch="sm_21" -c kernel.cu -o kernel.o
    $(CXX)  main.o `pkg-config --libs opencv` -L$(CUDA_INSTALL_PATH)/lib64 -lcudart kernel.o -o main

最佳答案

您可以尝试将所有 -l 选项放在 kernel.o 后面吗?

此致!

关于ubuntu - 在ubuntu中用cuda编译opencv的makefile停止工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11929006/

相关文章:

image - 值(value)观的作用

python - 从嘈杂的车牌上分割每个字符

C++ Tensorflow lite,某些函数的 undefined reference

c++ - Gnu Makefile - 处理依赖项

node.js - 从一个 docker 镜像运行多个服务器

.net - 尝试在 Linux 上将 Mpir.NET 与 F# 一起使用

c++ - ubuntu/linux/unix 中有带有 cbc 加密的 aes 256 吗?

c++ - 使用带有命名空间的 cvShowImage

c++ - gnu 使。仅重新编译未更改的文件

git - 无法从 Virtualbox 内的 Ubuntu 服务器上的 git 中提取