Unresolved External Symbols when using CUDA Driver API VS2012

孤人 提交于 2019-12-20 06:38:15

问题


I've been trying to use the CUDA driver API to load a .ptx file and a function from it with this code:

CUdevice device;
cuDeviceGet(&device,0);
CUcontext ctx;
cuCtxCreate(&ctx,0,device);
CUmodule mod;
cuModuleLoad(&mod,"kernel.ptx");
CUfunction func;
cuModuleGetFunction(&func,mod,"kernel");
CUdeviceptr ints;
cuMemAlloc(&ints,(sizeof(int)*30));

However at compile time I get these errors:

    1>kernel.cu.obj : error LNK2019: unresolved external symbol _cuDeviceGet@8 referenced in function _main
    1>kernel.cu.obj : error LNK2019: unresolved external symbol _cuCtxCreate_v2@12 referenced in function _main
    1>kernel.cu.obj : error LNK2019: unresolved external symbol _cuModuleLoad@8 referenced in function _main
    1>kernel.cu.obj : error LNK2019: unresolved external symbol _cuModuleGetFunction@12 referenced in function _main
    1>kernel.cu.obj : error LNK2019: unresolved external symbol _cuMemAlloc_v2@8 referenced in function _main
    1>kernel.cu.obj : error LNK2019: unresolved external symbol _cuMemcpyHtoD_v2@12 referenced in function _main
    1>kernel.cu.obj : error LNK2019: unresolved external symbol _cuMemcpyDtoH_v2@12 referenced in function _main
    1>kernel.cu.obj : error LNK2019: unresolved external symbol _cuLaunchKernel@44 referenced in function _main

I created a new CUDA 5.5 project in VS2012 and typed this directly into the generated .cu file however at compile time I got these errors. If I do a test that doesn't use the driver api I don't get any errors!


回答1:


Those errors occur when you are not linking against cuda.lib.




回答2:


For those who does not know how to add cuda.lib into linking process like me (using VS2017):

  1. Right click on the project, goto Properties at the bottom of the menu

  2. Goto Linker-->Input

  3. In Additional Dependencies, make sure that cuda.lib is there. In my case, this solved the 2019 link error.

  4. Besides, if you click on the edit item in the drop menu, there is a Macros button that you can click and view all pre-defined Macros in your VS project.



来源:https://stackoverflow.com/questions/19086281/unresolved-external-symbols-when-using-cuda-driver-api-vs2012

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!