这是我的make文件输出:
nvcc -c -arch=sm_35 src/kmeans_cuda.cu
nvcc -c -arch=sm_35 src/sequence.c
nvcc -c -arch=sm_35 src/io.c
nvcc -c -arch=sm_35 src/main.c
nvcc -g -o cuda-means kmeans_cuda.o sequence.o io.o main.o
Undefined symbols for architecture x86_64:
"_kmeans", referenced from:
_main in main.o
(maybe you meant: cudaError (anonymous namespace)::cudaLaunch<char>(char*))
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
make: *** [all] Error 1
在我的主函数上,我调用kmeans();
,kmeans是kmeans_cuda.cu中定义的C函数
void kmeans() {
long i,h,j,k; //counters
long delta; //Number of objects has diverged in current iteration
long nearest; //Nearest centroid
unsigned int distance,min_distance; //distance calculated by relation point-cluster
int *count,*recv_count;
int *send_label;
double begin,end,trans_init,trans_end;
// should call kernel, but is not calling yet, because it's not implemented ...
我已经尝试在kmeans()声明中添加__host__
,但是没有解决问题。
我现在知道为什么我得到这个错误,因为我将对象与函数链接。
答案 0 :(得分:4)
nvcc将.cu
文件视为C ++,并且您的主机代码位于.c
个文件中(即在C中,而不是C ++中)。
最简单的解决方案是简单地将您的.c
文件重命名为.cpp
,并将您的应用视为C ++应用而不是C.您还可以将kmeans()
声明为extern "C" {...}
强制编译器为函数使用C绑定而不是C ++绑定,但是你必须为每个未来的函数执行此操作,这可能是不必要的不优雅。