问题
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):
Right click on the project, goto
Propertiesat the bottom of the menuGoto
Linker-->InputIn
Additional Dependencies, make sure thatcuda.libis there. In my case, this solved the 2019 link error.Besides, if you click on the
edititem in the drop menu, there is aMacrosbutton 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