2

As I wanted to compile my program (using Cusparse) the following lines appeared:

tmp/tmpxft_00001048_00000000-13_matvec.o: In function main': tmpxft_00001048_00000000-1_matvec.cudafe1.cpp:(.text+0x6d5): undefined reference tocusparseCreate'

The same came out not only for cusparseCreate, but also for cusparseCreateMatDescr, cusparseSetMatType, cusparseSetMatIndexBase, cusparseXcoo2csr, cusparseDsctr, cusparseDcsrmv_v2, cusparseDestroyMatDescr and cusparseDestroy. What does it mean?

Luis G
  • 41
  • 1
  • 2
  • 1
    How are you compiling ? It looks like you are not linking against cusparse library. The answer on how to link against the library depends on the os. – Pavan Yalamanchili Mar 12 '12 at 21:30
  • 1
    How to solve same problem for windows visual studio 2010 ? – Terminal Nov 27 '12 at 08:44
  • @Terminal, here's how to solve the problem with visual studio: http://stackoverflow.com/questions/13570285/how-to-link-library-e-g-cublas-cusparse-for-cuda-on-windows – Veridian Nov 08 '16 at 17:21

1 Answers1

5

You need to link with the cuSPARSE library. Since you're using Linux, adding -lcusparse to your nvcc command line should be sufficient.

Note that you may also need to add the CUDA libraries path to your LD_LIBRARY_PATH environment variable if the system fails to find the linked libraries when executing.

Tom
  • 20,852
  • 4
  • 42
  • 54
  • Did I miss something or is there a way you deduced that the OP was using Linux from the question he asked ? – Pavan Yalamanchili Mar 13 '12 at 15:11
  • The error message is a typical Linux error message, Windows would say something like "unresolved external symbol". I don't know what Macs say so it's possible he is using a Mac, but in that case the resolution would be the same. For Windows one would add cusparse.lib alongside cudart.lib when following these instructions: http://stackoverflow.com/a/2047892/214473 (VS2005/2008) or http://stackoverflow.com/a/7285235/214473 (VS2010). – Tom Mar 13 '12 at 15:53
  • I see those error messages in our system all the time! It is ridiculous that I couldn't notice that. Thanks for clarifying. – Pavan Yalamanchili Mar 13 '12 at 17:14
  • Yes, indeed I am using Linux (Ububtu). Thanks for the advice. I adedd -lcusparse and it compiled. But now, I'm facing another problem. The thing is that I want to multiply a matrix with a vector (cusparseCcsrmv) using cuComplex variables. But altough the program compiles, it doesn't return the result. With kind of objects should the vectors be? The form of the function is: – Luis G Mar 15 '12 at 17:19
  • cusparseCcsrmv(cusparseHandle_t handle, cusparseOperation_t transA, int m, int n, int nnz, const cuComplex *alpha, const cusparseMatDescr_t descrA, const cuComplex *csrValA, const int *csrRowPtrA, const int *csrColIndA, const cuComplex *x, const cuComplex *beta, cuComplex *y) – Luis G Mar 15 '12 at 17:19
  • I'm aware that y and x are vectors, but I don't know how should they be saved. Should they be saved as dense or sparse vectors? – Luis G Mar 15 '12 at 17:20
  • @Terminal, here's how to solve the problem with VS: http://stackoverflow.com/questions/13570285/how-to-link-library-e-g-cublas-cusparse-for-cuda-on-windows – Veridian Nov 08 '16 at 17:20