VS2008无法编译cuda
简而言之,当我尝试在 IDE 中编译 VS2008 项目时,它会失败,但是当我在命令提示符下使用相同的命令行时,它会编译。有人可以帮忙吗?
详细信息
使用 VS2008
和 Cuda
工具包 3.2。还安装了 VS2010
。 执行以下操作:步骤 在开始该程序之前。
- 添加了自定义规则文件,位于:
C:\Program Files (x86)\NVIDIA GPUComputing Toolkit\CUDA\v3.2\extras\visual_studio_integration\rules
- 然后添加
C:\Program Files (x86)\NVIDIA GPUComputing Toolkit \CUDA\v3.2\lib\x64
到项目属性中的linker->general
以及cudart.lib
和cuda 中的其他库目录.lib
到其他依赖项。
如果我遗漏了什么,请告诉我。
cmd 提示符下 set 命令的输出是:
CUDA_BIN_PATH=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v3.2\\bin
CUDA_INC_PATH=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v3.2\\include
CUDA_LIB_PATH=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v3.2\\lib\x64
CUDA_PATH=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v3.2\
CUDA_PATH_V3_2=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v3.2\
哎呀,忘记了错误消息。
1>t.cu.obj : error LNK2019: unresolved external symbol ___cudaUnregisterFatBinary@4 referenced in function "void __cdecl __cudaUnregisterBinaryUtil(void)" (?__cudaUnregisterBinaryUtil@@YAXXZ)
1>t.cu.obj : error LNK2019: unresolved external symbol _cudaLaunch@4 referenced in function "enum cudaError __cdecl cudaLaunch<char>(char *)" (??$cudaLaunch@D@@YA?AW4cudaError@@PAD@Z)
1>t.cu.obj : error LNK2019: unresolved external symbol _cudaSetupArgument@12 referenced in function "void __cdecl __device_stub__Z12compute_sum4P6float4S0_S0_i(struct float4 *,struct float4 *,struct float4 *,int)" (?__device_stub__Z12compute_sum4P6float4S0_S0_i@@YAXPAUfloat4@@00H@Z)
1>t.cu.obj : error LNK2019: unresolved external symbol ___cudaRegisterFunction@40 referenced in function "void __cdecl __sti____cudaRegisterAll_47_tmpxft_00000ea8_00000000_8_t_compute_10_cpp1_ii_65ce9b46(void)" (?__sti____cudaRegisterAll_47_tmpxft_00000ea8_00000000_8_t_compute_10_cpp1_ii_65ce9b46@@YAXXZ)
1>t.cu.obj : error LNK2019: unresolved external symbol ___cudaRegisterFatBinary@4 referenced in function "void __cdecl __sti____cudaRegisterAll_47_tmpxft_00000ea8_00000000_8_t_compute_10_cpp1_ii_65ce9b46(void)" (?__sti____cudaRegisterAll_47_tmpxft_00000ea8_00000000_8_t_compute_10_cpp1_ii_65ce9b46@@YAXXZ)
1>t.cu.obj : error LNK2019: unresolved external symbol _cudaEventDestroy@4 referenced in function _main
1>t.cu.obj : error LNK2019: unresolved external symbol _cudaEventElapsedTime@12 referenced in function _main
1>t.cu.obj : error LNK2019: unresolved external symbol _cudaEventSynchronize@4 referenced in function _main
1>t.cu.obj : error LNK2019: unresolved external symbol _cudaConfigureCall@32 referenced in function _main
1>t.cu.obj : error LNK2019: unresolved external symbol _cudaEventRecord@8 referenced in function _main
1>t.cu.obj : error LNK2019: unresolved external symbol _cudaThreadSynchronize@0 referenced in function _main
1>t.cu.obj : error LNK2019: unresolved external symbol _cudaEventCreate@4 referenced in function _main
1>t.cu.obj : error LNK2019: unresolved external symbol _cudaMemcpy@16 referenced in function _main
1>t.cu.obj : error LNK2019: unresolved external symbol _cudaMalloc@8 referenced in function _main
1>D:\projects\cup1\Debug\cup1.exe : fatal error LNK1120: 14 unresolved externals
这是命令行:
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v3.2\\bin\nvcc.exe" -gencode=arch=compute_10,code=\"sm_10,compute_10\" -gencode=arch=compute_20,code=\"sm_20,compute_20\" --machine 32 -ccbin "C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin" -Xcompiler "/EHsc /W3 /nologo /O2 /Zi /MT " -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v3.2\\include" -maxrregcount=32 --compile -o "Debug/t.cu.obj" t.cu
In short, when I try to compile a VS2008
project inside the IDE, it fails, but when I use the same command line on command prompt, it compiles. Can anybody help?
Details
Using VS2008
with Cuda
toolkit 3.2. Also have VS2010
installed.
Did the following: steps before starting the procedure.
- Added a custom rule file, which was in:
C:\Program Files (x86)\NVIDIA GPU Computing Toolkit\CUDA\v3.2\extras\visual_studio_integration\rules
- Then added
C:\Program Files (x86)\NVIDIA GPU Computing Toolkit\CUDA\v3.2\lib\x64
to additional library directories inlinker->general
in project's properties andcudart.lib
andcuda.lib
to additional dependencies.
Please let me know if I'm missing something.
The output of set command on cmd prompt is:
CUDA_BIN_PATH=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v3.2\\bin
CUDA_INC_PATH=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v3.2\\include
CUDA_LIB_PATH=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v3.2\\lib\x64
CUDA_PATH=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v3.2\
CUDA_PATH_V3_2=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v3.2\
Oops, forgot the error messages.
1>t.cu.obj : error LNK2019: unresolved external symbol ___cudaUnregisterFatBinary@4 referenced in function "void __cdecl __cudaUnregisterBinaryUtil(void)" (?__cudaUnregisterBinaryUtil@@YAXXZ)
1>t.cu.obj : error LNK2019: unresolved external symbol _cudaLaunch@4 referenced in function "enum cudaError __cdecl cudaLaunch<char>(char *)" (??$cudaLaunch@D@@YA?AW4cudaError@@PAD@Z)
1>t.cu.obj : error LNK2019: unresolved external symbol _cudaSetupArgument@12 referenced in function "void __cdecl __device_stub__Z12compute_sum4P6float4S0_S0_i(struct float4 *,struct float4 *,struct float4 *,int)" (?__device_stub__Z12compute_sum4P6float4S0_S0_i@@YAXPAUfloat4@@00H@Z)
1>t.cu.obj : error LNK2019: unresolved external symbol ___cudaRegisterFunction@40 referenced in function "void __cdecl __sti____cudaRegisterAll_47_tmpxft_00000ea8_00000000_8_t_compute_10_cpp1_ii_65ce9b46(void)" (?__sti____cudaRegisterAll_47_tmpxft_00000ea8_00000000_8_t_compute_10_cpp1_ii_65ce9b46@@YAXXZ)
1>t.cu.obj : error LNK2019: unresolved external symbol ___cudaRegisterFatBinary@4 referenced in function "void __cdecl __sti____cudaRegisterAll_47_tmpxft_00000ea8_00000000_8_t_compute_10_cpp1_ii_65ce9b46(void)" (?__sti____cudaRegisterAll_47_tmpxft_00000ea8_00000000_8_t_compute_10_cpp1_ii_65ce9b46@@YAXXZ)
1>t.cu.obj : error LNK2019: unresolved external symbol _cudaEventDestroy@4 referenced in function _main
1>t.cu.obj : error LNK2019: unresolved external symbol _cudaEventElapsedTime@12 referenced in function _main
1>t.cu.obj : error LNK2019: unresolved external symbol _cudaEventSynchronize@4 referenced in function _main
1>t.cu.obj : error LNK2019: unresolved external symbol _cudaConfigureCall@32 referenced in function _main
1>t.cu.obj : error LNK2019: unresolved external symbol _cudaEventRecord@8 referenced in function _main
1>t.cu.obj : error LNK2019: unresolved external symbol _cudaThreadSynchronize@0 referenced in function _main
1>t.cu.obj : error LNK2019: unresolved external symbol _cudaEventCreate@4 referenced in function _main
1>t.cu.obj : error LNK2019: unresolved external symbol _cudaMemcpy@16 referenced in function _main
1>t.cu.obj : error LNK2019: unresolved external symbol _cudaMalloc@8 referenced in function _main
1>D:\projects\cup1\Debug\cup1.exe : fatal error LNK1120: 14 unresolved externals
This is the command line:
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v3.2\\bin\nvcc.exe" -gencode=arch=compute_10,code=\"sm_10,compute_10\" -gencode=arch=compute_20,code=\"sm_20,compute_20\" --machine 32 -ccbin "C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin" -Xcompiler "/EHsc /W3 /nologo /O2 /Zi /MT " -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v3.2\\include" -maxrregcount=32 --compile -o "Debug/t.cu.obj" t.cu
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您正在使用 32 位 (
--machine 32
) 的 nvcc 进行编译,但链接的 cuda 库是 64 位 ([..]\lib\x64
)。You are compiling with nvcc for 32bit (
--machine 32
) but your linked cuda libs are 64bit ([..]\lib\x64
).nvcc 不仅是一个编译器,还可以用于链接。
但是,当您在 VS2008 中工作时,链接阶段是由 VS 执行的。您必须告诉它包含附加的 cuda 库文件。
在您的项目属性中设置:
配置属性 ->链接器->一般的。设置:“附加库目录”以包含 CUDA lib 目录。值 $(CUDA_LIB_PATH) 应该足以满足您的情况,因为此环境变量指向正确的方向
配置属性 ->链接器->输入。设置:“附加依赖项”为“cudart.lib”
nvcc is not only a compiler but can be also used for linking.
However, when you work in VS2008, the linking stage is performed by VS. You have to tell it to include additional cuda library files.
In your project properties set:
Configuration Properties -> Linker -> General. Set: "Additional Library Directories" to include CUDA lib directory. Value $(CUDA_LIB_PATH) should suffice in your case, as this environment variable points in the correct direction
Configuration Properties -> Linker -> Input. Set: "Additional Dependencies" to "cudart.lib"
请确保两件事:
您已在“附加输入”中添加了 cudart.lib。
cudart.lib和cudartxx_xx_x.dll的路径在VC++目录中设置。另外,将cuda dll的路径添加到系统的环境变量中。
以下是分步指南:Run CUDA on Visual Studio 2008
Make sure about two things:
You've added cudart.lib in Additional Inputs.
The path to cudart.lib and cudartxx_xx_x.dll is set in VC++ directories. Also add the path of cuda dll into your system's environment variables.
Here's a step by step guide: Run CUDA on Visual Studio 2008