Linker issue with CUDA API libraries



  • Hi! I want to add Nvidia CUDA API to Qt (OS: Windows | Qt 5.7.1).

    I have included:

    .pro file
    
    INCLUDEPATH += "C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v8.0\\include"
    
    win32 {
        contains(QMAKE_TARGET.arch, x86_64) {
          LIBS += "C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v8.0\\lib\\x64\\cudadevrt.lib"
        } else {
          LIBS += "C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v8.0\\lib\\Win32\\cudadevrt.lib"
        }
    }
    
    test.h file
    #include <cuda_runtime.h>
    

    I get errors in test.cpp :

    Screenshot:

    alt text

    I have test it in Visual Studio 2015 as console project and it works, but not in Qt.

    How to fix it? Thanks in advance.


  • Moderators

    That's not how you pass libraries to the linker. Change this:

    LIBS += "C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v8.0\\lib\\x64\\cudadevrt.lib"
    

    to

    LIBS += -L"C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v8.0/lib/x64" -lcudadevrt
    

    That's -L for the path and -l(lowercase L) for the library name without the extension.
    After that re-run qmake (menu Build->Run qmake).



  • @Chris-Kawa

    I have changed to:

    INCLUDEPATH += "C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v8.0\\include"
    
    win32 {
        contains(QMAKE_TARGET.arch, x86_64) {
          LIBS += -L"C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v8.0/lib/x64" -lcudadevrt
        } else {
          LIBS += -L"C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v8.0/lib/Win32" -lcudadevrt
        }
    }
    

    Run clean/run qmake/build but the errors still exists.



  • @Chris-Kawa

    I have found the bug and fixed. Thanks.


Log in to reply