Cuda 使用CUSPARSE时遇到问题

Cuda 使用CUSPARSE时遇到问题,cuda,Cuda,当我想编译我的程序(使用Cusparse)时,出现了以下几行代码: tmp/tmpxft_00001048_u00000000-13_matvec.o:在函数main'中: tmpxft_00001048_00000000-1_matvec.cudafe1.cpp:(.text+0x6d5):对cusparseCreate'的未定义引用 同样的结果不仅适用于cusparseCreate,也适用于cusparseCreateMatDescr、cusparseSetMatType、cusparseS

当我想编译我的程序(使用Cusparse)时,出现了以下几行代码:

tmp/tmpxft_00001048_u00000000-13_matvec.o:在函数
main'中:
tmpxft_00001048_00000000-1_matvec.cudafe1.cpp:(.text+0x6d5):对
cusparseCreate'的未定义引用

同样的结果不仅适用于cusparseCreate,也适用于cusparseCreateMatDescr、cusparseSetMatType、cusparseSetMatIndexBase、cusparseXcoo2csr、CusParsedCtr、,
cusparseDcsrmv_v2、cusparseDestroyMatDescr和cusparseDestroy。这是什么意思?

您需要链接到cuSPARSE库。由于您使用的是Linux,将
-lcusparse
添加到nvcc命令行就足够了


请注意,如果系统在执行时无法找到链接的库,则可能还需要将CUDA库路径添加到LD_LIBRARY_path环境变量。

您是如何编译的?看起来您没有链接到cusparse库。关于如何链接库的答案取决于操作系统。如何解决windows visual studio 2010的相同问题?@Terminal,下面是如何解决visual studio的问题:我是否遗漏了什么,或者您是否有办法从OP提出的问题推断出他使用Linux?错误消息是典型的Linux错误消息,Windows会说“未解析的外部符号”。我不知道Mac电脑是怎么说的,所以他可能在使用Mac电脑,但在这种情况下,分辨率是一样的。对于Windows,在遵循以下说明(VS2005/2008)或(VS2010)时,会在cudart.lib旁边添加cusparse.lib。我在系统中一直看到这些错误消息!我竟然没有注意到这一点,真是可笑。谢谢你的澄清。是的,我确实在使用Linux(Ububtu)。谢谢你的建议。我写了一篇论文,并编译了它。但现在,我面临另一个问题。问题是我想用一个向量乘以一个矩阵(cusparseCcsrmv),使用cuComplex变量。但是,尽管程序进行了编译,但它不会返回结果。向量应该是什么样的对象?函数的形式是:cusparseCcsrmv(cusparseHandle\u t handle,cusparseOperation\u t transA,int m,int n,int nnz,const cuComplex*alpha,const cusparseMatDescr\u t descrA,const cuComplex*csrValA,const int*csrRowPtrA,const int*csrColIndA,const cuComplex*x,const cuComplex*beta,cuComplex*y)