在c++中链接Cuda问题
Linking Cuda in C++ issue
我已经搜索了现有的问题,但我似乎无法解决这个问题。
我有一个blur_mask。Cc文件:
#include <iostream>
#include <ctime>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/gpu/gpu.hpp>
#include <vector_types.h>
#include <cuda.h>
#include <cuda_runtime.h>
extern "C" void gpuBlurMask(unsigned char* srcData, int srcStep, uchar3* dst, int dstStep, int width, int height, float *mask, int maskStep, int maskWidth, int maskHeight, int blockSize=16);
using namespace std;
using namespace cv;
using namespace cv::gpu;
void blurMask(Mat& src, Mat& dst, Mat& mask) {
GpuMat gpuSrc, gpuDst, gpuMask;
gpuSrc.upload(src);
gpuDst.upload(dst);
gpuMask.upload(mask);
gpuBlurMask(gpuSrc.data, gpuSrc.step, gpuDst.ptr<uchar3>(), gpuDst.step, gpuSrc.cols, gpuSrc.rows, gpuMask.ptr<float>(), gpuMask.step, gpuMask.cols, gpuMask.rows);
gpuDst.download(dst);
}
...
和gpu_blur。包含
的Cu文件extern "C"
void gpuBlurMask(unsigned char* srcData, int srcStep, uchar3* dst, int dstStep, int width, int height, float *mask, int maskStep, int maskWidth, int maskHeight, int blockSize=16) {
...
当我做
nvcc -c -o gpu_blur gpu_blur.cu
没有错误,但是当编译
时g++ -o blur_mask blur_mask.cc gpu_blur -I /usr/local/cuda/include/ -lopencv_core -lopencv_highgui -lopencv_gpu
得到以下错误:
g++ -o blur_mask blur_mask.cc gpu_blur -I /usr/local/cuda/include/ -lopencv_core -lopencv_highgui -lopencv_gpu -lcuda
gpu_blur: In function `gpuBlurMask':
tmpxft_00000905_00000000-3_gpu_blur.cudafe1.cpp:(.text+0x59): undefined reference to `cudaMallocArray'
tmpxft_00000905_00000000-3_gpu_blur.cudafe1.cpp:(.text+0xa0): undefined reference to `cudaMemcpy2DToArray'
tmpxft_00000905_00000000-3_gpu_blur.cudafe1.cpp:(.text+0x139): undefined reference to `cudaConfigureCall'
tmpxft_00000905_00000000-3_gpu_blur.cudafe1.cpp:(.text+0x16f): undefined reference to `cudaDeviceSynchronize'
gpu_blur: In function `__cudaUnregisterBinaryUtil()':
tmpxft_00000905_00000000-3_gpu_blur.cudafe1.cpp:(.text+0x184): undefined reference to `__cudaUnregisterFatBinary'
gpu_blur: In function `__device_stub__Z14blurMaskKernelP6uchar3iiiPfiii(uchar3*, int, int, int, float*, int, int, int)':
tmpxft_00000905_00000000-3_gpu_blur.cudafe1.cpp:(.text+0x1b9): undefined reference to `cudaSetupArgument'
tmpxft_00000905_00000000-3_gpu_blur.cudafe1.cpp:(.text+0x1dc): undefined reference to `cudaSetupArgument'
tmpxft_00000905_00000000-3_gpu_blur.cudafe1.cpp:(.text+0x1ff): undefined reference to `cudaSetupArgument'
tmpxft_00000905_00000000-3_gpu_blur.cudafe1.cpp:(.text+0x222): undefined reference to `cudaSetupArgument'
tmpxft_00000905_00000000-3_gpu_blur.cudafe1.cpp:(.text+0x245): undefined reference to `cudaSetupArgument'
gpu_blur:tmpxft_00000905_00000000-3_gpu_blur.cudafe1.cpp:(.text+0x264): more undefined references to `cudaSetupArgument' follow
gpu_blur: In function `__nv_cudaEntityRegisterCallback(void**)':
tmpxft_00000905_00000000-3_gpu_blur.cudafe1.cpp:(.text+0x381): undefined reference to `__cudaRegisterFunction'
tmpxft_00000905_00000000-3_gpu_blur.cudafe1.cpp:(.text+0x3af): undefined reference to `__cudaRegisterTexture'
gpu_blur: In function `__sti____cudaRegisterAll_43_tmpxft_00000905_00000000_6_gpu_blur_cpp1_ii_srcTex()':
tmpxft_00000905_00000000-3_gpu_blur.cudafe1.cpp:(.text+0x3c3): undefined reference to `__cudaRegisterFatBinary'
gpu_blur: In function `cudaChannelFormatDesc cudaCreateChannelDesc<unsigned char>()':
tmpxft_00000905_00000000-3_gpu_blur.cudafe1.cpp:(.text._Z21cudaCreateChannelDescIhE21cudaChannelFormatDescv[cudaChannelFormatDesc cudaCreateChannelDesc<unsigned char>()]+0x34): undefined reference to `cudaCreateChannelDesc'
gpu_blur: In function `cudaError cudaBindTextureToArray<unsigned char, 2, (cudaTextureReadMode)0>(texture<unsigned char, 2, (cudaTextureReadMode)0> const&, cudaArray const*, cudaChannelFormatDesc const&)':
tmpxft_00000905_00000000-3_gpu_blur.cudafe1.cpp:(.text._Z22cudaBindTextureToArrayIhLi2EL19cudaTextureReadMode0EE9cudaErrorRK7textureIT_XT0_EXT1_EEPK9cudaArrayRK21cudaChannelFormatDesc[cudaError cudaBindTextureToArray<unsigned char, 2, (cudaTextureReadMode)0>(texture<unsigned char, 2, (cudaTextureReadMode)0> const&, cudaArray const*, cudaChannelFormatDesc const&)]+0x27): undefined reference to `cudaBindTextureToArray'
gpu_blur: In function `cudaError cudaLaunch<char>(char*)':
tmpxft_00000905_00000000-3_gpu_blur.cudafe1.cpp:(.text._Z10cudaLaunchIcE9cudaErrorPT_[cudaError cudaLaunch<char>(char*)]+0x14): undefined reference to `cudaLaunch'
collect2: ld returned 1 exit status
谢谢。
您需要链接到cudart库(-L/usr/local/cuda/lib64 -lcudart
)
相关文章:
- 基本 Cuda C++项目集成问题
- 在本地安装OpenMPI的问题与CUDA一起使用
- 如何调试错误代码 77:cudaErrorIllegal地址当 cuda-memcheck 没有发现问题时
- 我正在尝试运行CUDA示例,但是我在Ubuntu 16.04 Lts上的OpenGL(libglew.a)有问题
- CUDA中的存储器计算重叠问题
- 是否有可能解决 CUDA 内存碎片问题
- CUDA 内存管理/类问题中的指针
- CUDA:使用 tex2D() 的问题
- CUDA 共享内存理解问题
- 链接 CUDA 编译与使用提升的代码时出现问题
- 在将复杂数据从主机传输到设备的简单 CUDA 代码中出现问题
- Cuda:固定内存零复制问题
- 与OpenMP,MPI和CUDA链接时的Autotools问题
- CUDA推力内存分配问题
- CUDA和C++函数问题(Visual Studio 2013)
- 在c++中链接Cuda问题
- 从静态初始化代码启动CUDA内核时遇到问题
- insight eclipse版索引器的CUDA 7.5问题
- Cuda无人模拟-共享内存问题
- CUDA编译问题