CUDA链接错误 - Visual Express 2008 - 由于(null)配置文件导致的nvcc致命错误

时间:2010-06-03 23:22:13

标签: c++ visual-c++ cuda windows-xp linker-errors

在过去的两周里,我一直在寻找可能的错误解决方案。我已经成功安装了Cuda 64位编译器(工具)和SDK以及64位版本的Visual Studio Express 2008和带有Framework 3.5的Windows 7 SDK。我正在使用Windows XP 64位。我已经确认VSE能够以64位编译,因为我使用以下网站上的步骤可以使用所有64位选项:(因为Visual Express本身并不包含64位软件包)

http://jenshuebel.wordpress.com/2009/02/12/visual-c-2008-express-edition-and-64-bit-targets/

64位安装的注册表更新可在与上述链接相同的页面上的用户注释中找到。

我已经确认了64位编译能力,因为“工具 - >选项 - > VC ++目录”下的“x64”可从下拉菜单中获得,并且64位编译不会导致整个项目被“跳过”。我已经包含了64位cuda工具,64 SDK和Visual Express(\ VC \ bin \ amd64)所需的所有目录。

这是尝试以64位编译时收到的错误消息:

1>------ Build started: Project: New, Configuration: Release x64 ------
1>Compiling with CUDA Build Rule...
1>"C:\CUDA\bin64\nvcc.exe"    -arch sm_10 -ccbin "C:\Program Files (x86)\Microsoft    Visual Studio 9.0\VC\bin"    -Xcompiler "/EHsc /W3 /nologo /O2 /Zi   /MT  "  -maxrregcount=32  --compile -o "x64\Release\template.cu.obj" "c:\Documents and Settings\All Users\Application Data\NVIDIA Corporation\NVIDIA GPU Computing SDK\C\src\CUDA_Walkthrough_DeviceKernels\template.cu" 
1>nvcc fatal   : Visual Studio configuration file '(null)' could not be found for installation at 'C:/Program Files (x86)/Microsoft Visual Studio 9.0/VC/bin/../..'
1>Linking...
1>LINK : fatal error LNK1181: cannot open input file '.\x64\Release\template.cu.obj'
1>Build log was saved at "file://c:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\Projects\New\New\x64\Release\BuildLog.htm"
1>New - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

这是我试图以64位编译/运行的简单代码:

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>

#include <cuda.h>

void mypause () 
{ 
  printf ( "Press [Enter] to continue . . ." );
  fflush ( stdout );
  getchar();
} 

__global__ void VecAdd1_Kernel(float* A, float* B, float* C, int N)
{
 int i = blockDim.x*blockIdx.x+threadIdx.x;
 if (i<N)
  C[i] = A[i] + B[i]; //result should be a 16x1 array of 250s
} 

__global__ void VecAdd2_Kernel(float* B, float* C, int N)
{
 int i = blockDim.x*blockIdx.x+threadIdx.x;
 if (i<N)
  C[i] = C[i] + B[i]; //result should be a 16x1 array of 400s
}

int main()
{
 int N = 16;
 float A[16];float B[16];
 size_t size = N*sizeof(float);

 for(int i=0; i<N; i++) 
 {
  A[i] = 100.0;
  B[i] = 150.0;
 }

 // Allocate input vectors h_A and h_B in host memory
 float* h_A = (float*)malloc(size);
        float* h_B = (float*)malloc(size);
        float* h_C = (float*)malloc(size);

 //Initialize Input Vectors
 memset(h_A,0,size);memset(h_B,0,size);
 h_A = A;h_B = B;

 printf("SUM = %f\n",A[1]+B[1]); //simple check for initialization

 //Allocate vectors in device memory
 float* d_A;
 cudaMalloc((void**)&d_A,size);
 float* d_B;
 cudaMalloc((void**)&d_B,size);
 float* d_C;
 cudaMalloc((void**)&d_C,size);

 //Copy vectors from host memory to device memory
 cudaMemcpy(d_A,h_A,size,cudaMemcpyHostToDevice);
 cudaMemcpy(d_B,h_B,size,cudaMemcpyHostToDevice);

 //Invoke kernel
 int threadsPerBlock = 256;
 int blocksPerGrid = (N+threadsPerBlock-1)/threadsPerBlock;
 VecAdd1(blocksPerGrid, threadsPerBlock,d_A,d_B,d_C,N);
 VecAdd2(blocksPerGrid, threadsPerBlock,d_B,d_C,N);

 //Copy results from device memory to host memory
 //h_C contains the result in host memory
 cudaMemcpy(h_C,d_C,size,cudaMemcpyDeviceToHost);

 for(int i=0; i<N; i++) //output result from the kernel "VecAdd"
 {
  printf("%f ", h_C[i] );
  printf("\n");
 }
 printf("\n");

 cudaFree(d_A); 
 cudaFree(d_B); 
 cudaFree(d_C);
 free(h_A);
 free(h_B);
 free(h_C);

 mypause();
 return 0;
}

4 个答案:

答案 0 :(得分:19)

我通过

解决了这个问题
  1. 安装Windows SDK(不要忘记为64位操作系统选择所有x64选项)
  2. 在PATH中包含“c:\ Program Files(x86)\ Microsoft Visual Studio 10.0 \ VC \ bin \ amd64”
  3. 在目录“c:\ Program Files(x86)\ Microsoft Visual Studio 10.0 \ VC \ bin \ amd64”中创建文件vcvars64.bat,其中包含以下内容: 调用“C:\ Program Files \ Microsoft SDKs \ Windows \ v7.1 \ Bin \ SetEnv.cmd”/ x64
  4. 注意:我这样做是因为:

    1. 我正在使用VC ++ Express 2010
    2. 我在任何目录中都没有“vcvars64.bat”?

答案 1 :(得分:4)

更新06/04/2010:

好的,我找到了问题的解决方案。代码很好。按照上面的原始链接中的步骤并添加所需的注册表项后,通过从开始菜单启动Windows SDK配置工具,确保Windows SDK定位到正确的版本(7.0),选择正确的版本(v7.0),然后单击“生成当前”。

确保包含以下x64编译目录(在“工具 - &gt;选项 - &gt;项目和解决方案 - > VC ++目录”下): C:\ CUDA \ bin64适用 C:\ CUDA \ lib64的 C:\ CUDA \包括 C:\ Program Files(x86)\ Microsoft Visual Studio 9.0 \ VC \ bin \ amd64

现在还有另一件事要改变64位系统。显然,cuda编译器在Visual Express 2008上有64位编译器的“硬编码”目录。要进行修复,请复制所需的文件“vcvars64.bat”并将其重命名为“vcvarsamd64.bat”,如下所示:

C:\ Program Files(x86)\ Microsoft Visual Studio 9.0 \ VC \ bin \ vcvars64.bat

C:\ Program Files(x86)\ Microsoft Visual Studio 9.0 \ VC \ bin \ amd64 \ vcvarsamd64.bat

更改后,程序编译并成功运行。

我已经在网上阅读了“其他”帖子以获取错误的其他解决方案:“nvcc致命:Visual Studio配置文件'(null)'”,但很少有人指定以上作为获取nvcc的要求找到必要的visual studio配置文件。

免责声明:我已安装到干净的机器和操作系统。

希望这有助于其他有类似问题的人。

答案 2 :(得分:3)

相同的错误消息,但又有不同的解决方案。我试图在64位机器上编译32位CUDA库。 我必须在--machine 32电话中添加nvcc参数,正如Imperian在评论中所建议的那样:Error compiling CUDA from Command Prompt

希望这有助于某人

答案 3 :(得分:1)

我发现我还必须更改CUDA_PATH和CUDA_LIB_PATH环境变量,因为它们指向x86工具链(我在x64工具之后安装)。

在遇到一些链接器错误后,我设法构建了一个x64 CUDA应用程序!