how to link library (e.g. CUBLAS, CUSPARSE) for CUDA on windows

The general instructions for linking libraries is not specific to CUDA. So you may want to learn more about using MS VS. Anyway, the steps are like this:

  1. Make sure you have opened the project that you want to work on.
  2. Select View…Property Pages (from the menu) A new dialog box will open up.
  3. On the left hand side of this dialog box, select Linker to open up it’s sub-menu
  4. Under linker, select Input
  5. Now, on the pane on the right, observe the first item which is “Additional Dependencies”. I believe cudart.lib should already be present there.
  6. Click to the right of cudart.lib You can now type in new libraries to be added. Type a space (to separate from cudart.lib) and type cusparse.lib
  7. Now click “Apply” in the lower right corner of the dialog box.

That should be all that’s needed, if your project/solution file is already set up using a cuda template. If cudart.lib is not present, or your project/solution files do not already comprehend cuda, that is a separate issue. In that case I would recommend starting over, by cloning a project from the Samples, and building your project using that as a starting point. It will then pick up all the proper directories to search as well as the cuda build rules. Since all the main cuda libraries (cudart, cublas, cufft, cusparse, etc.) are all in the same location, the same search path should pick any of them up as needed.

If you wanted to link another library, such as cublas.lib, for example, you could follow a similar sequence, replacing cusparse.lib above with cublas.lib

Note that with newer versions of CUDA (e.g. CUDA 7.5) it will be necessary to build a 64-bit project only (follow the above steps when modifying the x64 project properties.) CUDA 7.5 and beyond are dropping support for 32-bit projects.

Leave a Comment