gcc与CUDA问题
嗨,
我编译了一个CUDA共享库,但无法将它与使用它的主程序链接起来。我正在和gcc一起编写主程序。
代码:
simplemain.c
#include <stdio.h>
#include <stdlib.h>
void fcudadriver();
int main()
{
printf("Main \n");
fcudadriver();
return 0;
}test.cu
__global__ void fcuda()
{
}
void fcudadriver()
{
fcuda<<<1,1>>>();
}我将test.cu编译为-->它可以工作
nvcc --compiler-options '-fPIC' -o libtest.so --shared test.cu我将simplemain.c编译为->它给出错误:(
gcc simplemain.c -L. -ltest
/tmp/ccHnB4Vh.o:simplemain.c:function main: error: undefined reference to 'fcudadriver'
collect2: ld returned 1 exit status发布于 2013-01-20 13:51:06
试试用g++代替gcc吧。nvcc使用c++样式链接约定。(您不需要重命名任何文件。)
或者,如果您必须使用gcc,请在您的void fcudadriver()函数定义前添加如下内容:
extern "C" void fcudadriver()发布于 2013-01-20 13:45:11
C和C++以不同的方式命名函数。
由于nvcc将.cu文件中的CPU代码视为C++,因此您可以将simplemain.c重命名为simplemain.cpp,并使用g++编译它
另一种解决方案是在.cu文件中的函数定义之前添加extern "C"。
https://stackoverflow.com/questions/14421898
复制相似问题