Cuda C - Linker error - undefined reference

血红的双手。 提交于 2019-11-26 22:42:49

You have a problem with symbol name mangling. nvcc uses the host C++ compiler to compile host code, and this implies that symbol name mangling is applied to code emitted by the CUDA toolchain.

There are two solutions to this problem. The first is to define dummy_gpu using C linkage, so change your my_cuda.cu to something like this:

extern "C" {
#include "my_cuda.h"
}

.....


extern "C"
void dummy_gpu(){
   dummy_gpu_kernel<<<128,128>>>();
}

Note that you will need to change your linkage command to this:

gcc -L/usr/local_rwth/sw/cuda/5.0.35/lib64 -o md.exe main.o my_cuda.o -lcuda -lcudart 

because the CUDA shared libraries need to be specified after the object files that use them.

Your second alternative would be to use either g++ or nvcc to do the linking, in which case the whole problem should disappear.

You have a C/C++ linkage problem. nvcc is decorating things in a C++ fashion but your gcc compiler is handling things using C style linkage. A simple way to fix it is to rename your main.c to main.cpp and then repeat your commands using g++ instead of gcc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!