Cuda cusolver can't link in Visual studio 2013

2019-02-21 02:04发布

问题:

I have tried basically everything and I can't get vs2013 to compile and link against the cusolver library. I have tried all the sample projects that came with the cuda installation package and basically all of the samples work fine. Though there are no samples using cusolver. The include files work just fine. The linker is in error and all of the other cuda stuff links just fine. I tried adding one line of cusolver code to a perfectly working cuda sample and it breaks. Here is the code snippet:

#include "cuda_runtime.h"
#include "device_launch_parameters.h"
#include "cusolver_common.h"
#include "cusolverDn.h"
#include <stdio.h>

cudaError_t addWithCuda(int *c, const int *a, const int *b, unsigned int size);

__global__ void addKernel(int *c, const int *a, const int *b)
{
    int i = threadIdx.x;
    c[i] = a[i] + b[i];
}

int main()
{
    cusolverDnCreate(new cusolverDnHandle_t);

    return 0;
}

The build output is:

1>------ Build started: Project: The cudan, Configuration: Release x64 ------
1>  Compiling CUDA source file kernel.cu...
1>  
1>  c:\Users\Gdizzle\documents\visual studio 2013\Projects\The cudan\The cudan>"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v7.0\bin\nvcc.exe" -gencode=arch=compute_20,code=\"sm_20,compute_20\" --use-local-env --cl-version 2013 -ccbin "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\x86_amd64"  -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v7.0\include" -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v7.0\include"     --keep-dir x64\Release -maxrregcount=0  --machine 64 --compile -cudart static     -DWIN32 -DWIN64 -DNDEBUG -D_CONSOLE -D_MBCS -Xcompiler "/EHsc /W3 /nologo /O2 /Zi  /MD  " -o x64\Release\kernel.cu.obj "c:\Users\Gdizzle\documents\visual studio 2013\Projects\The cudan\The cudan\kernel.cu" 
1>  kernel.cu
1>kernel.cu.obj : error LNK2001: unresolved external symbol cusolverDnCreate
1>c:\users\gdizzle\documents\visual studio 2013\Projects\The cudan\x64\Release\The cudan.exe : fatal error LNK1120: 1 unresolved externals

I've tried adding directories in project properties -> vc++ and in linker options and that didn't help. Any ideas? It's so weird that this 1 Library doesn't work.

(Also if you have any other ideas on how to solve a systems of equations with least squares using gpu programming that would be helpful)

EDIT UPDATE: You must not include extra .h files nor extra libs by adding additional libraries or additional include directories in other linker options like cudaLinker or vc++ directories

回答1:

I've just tested this on Windows 7 64-bit, Visual Studio 2013 Community, CUDA 7.

  1. start by opening the vectorAdd cuda sample code. Be sure you can build this code correctly. (It should be a x64 project. CUDA 7 does not support 32-bit projects or operating systems on windows.) If you can't build this correctly, your issue has nothing to do with cusolver

  2. Add the following header file at the top of vectorAdd.cu:

    #include <cusolverDn.h>
    
  3. Add the following two lines to the beginning of the main routine:

    cusolverDnHandle_t my_handle;
    cusolverDnCreate(&my_handle);
    
  4. Go to Project...vectorAdd Properties...Linker...Input...Additional Dependencies. In this field you should already find a number of libraries including cudart_static.lib. Click in this field, then click on the drop-down menu arrow on the right, then click on <Edit...> At the bottom of the list of libraries in the edit window, add cusolver.lib on its own line.

  5. Rebuild the project.