VS2008没有编译cuda

问题描述:

总之,当我尝试在IDE内编译一个VS2008项目时,它失败了,但是当我在命令提示符下使用相同的命令行时,它会编译。任何人都可以帮忙吗?VS2008没有编译cuda

详细

使用VS2008Cuda工具包3.2。还安装了VS2010。 在开始操作之前做了以下操作:steps

  1. 添加自定义规则文件,该文件是: C:\Program Files (x86)\NVIDIA GPU Computing Toolkit\CUDA\v3.2\extras\visual_studio_integration\rules
  2. 在项目的属性linker->generalcudart.libcuda.lib然后加入C:\Program Files (x86)\NVIDIA GPU Computing Toolkit\CUDA\v3.2\lib\x64附加库目录额外的依赖。

请让我知道如果我失去了一些东西。

上CMD提示符的输出设定命令的是:

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 [email protected] referenced in function "void __cdecl __cudaUnregisterBinaryUtil(void)" ([email protected]@YAXXZ) 
1>t.cu.obj : error LNK2019: unresolved external symbol [email protected] referenced in function "enum cudaError __cdecl cudaLaunch<char>(char *)" ([email protected]@@[email protected]@[email protected]) 
1>t.cu.obj : error LNK2019: unresolved external symbol _cudaSetupArgume[email protected] referenced in function "void __cdecl __device_stub__Z12compute_sum4P6float4S0_S0_i(struct float4 *,struct float4 *,struct float4 *,int)" ([email protected]@[email protected]@[email protected]) 
1>t.cu.obj : error LNK2019: unresolved external symbol [email protected] referenced in function "void __cdecl __sti____cudaRegisterAll_47_tmpxft_00000ea8_00000000_8_t_compute_10_cpp1_ii_65ce9b46(void)" (?__sti____cudaRegister[email protected]@YAXXZ) 
1>t.cu.obj : error LNK2019: unresolved external symbol [email protected] referenced in function "void __cdecl __sti____cudaRegisterAll_47_tmpxft_00000ea8_00000000_8_t_compute_10_cpp1_ii_65ce9b46(void)" (?__sti____cudaRegister[email protected]@YAXXZ) 
1>t.cu.obj : error LNK2019: unresolved external symbol [email protected] referenced in function _main 
1>t.cu.obj : error LNK2019: unresolved external symbol [email protected] referenced in function _main 
1>t.cu.obj : error LNK2019: unresolved external symbol [email protected] referenced in function _main 
1>t.cu.obj : error LNK2019: unresolved external symbol [email protected] referenced in function _main 
1>t.cu.obj : error LNK2019: unresolved external symbol [email protected] referenced in function _main 
1>t.cu.obj : error LNK2019: unresolved external symbol [email protected] referenced in function _main 
1>t.cu.obj : error LNK2019: unresolved external symbol [email protected] referenced in function _main 
1>t.cu.obj : error LNK2019: unresolved external symbol [email protected] referenced in function _main 
1>t.cu.obj : error LNK2019: unresolved external symbol [email protected] 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 
+2

请不要让我们猜测的错误消息。 –

+0

是的,什么是错误信息? – jwdmsd

您正在使用NVCC编译为32位(--machine 32),但你的链接CUDA库是64位([..]\lib\x64)。

+0

这工作。但是,我想知道为什么我能够在命令行上编译我的程序。 – 0fnt

+0

您使用x86还是x64命令提示符?这可能会影响到这个等式。 – peakxu

NVCC不仅是一个编译器,但也可以用于连接。

但是,当您在VS2008中工作时,链接阶段由VS执行。你必须告诉它包含额外的cuda库文件。

在项目属性中设置:

  • 配置属性 - >链接器 - >常规。设置:“其他库目录”以包含CUDA lib目录。在您的情况下,值$(CUDA_LIB_PATH)应该就足够了,因为此环境变量指向正确的方向

  • 配置属性 - >链接器 - >输入。设置: “附加依赖” 到 “cudart.lib”

+0

正如我在前面的步骤中提到的,我已经完成了这些。 – 0fnt

+0

必须错过。对不起 – CygnusX1

确保两两件事:

  1. 你已加入cudart.lib在附加输入。

  2. cudart.libcudartxx_xx_x.dll在VC++目录上设置的路径。还要将cuda dll的路径添加到系统的环境变量中。

这里有一个一步一步的指导:Run CUDA on Visual Studio 2008