【问题标题】:Unable to compile CUDA C sources. Simple version is provided无法编译 CUDA C 源代码。提供简单版
【发布时间】:2012-04-13 01:36:09
【问题描述】:

问题来了…… 对于学校项目,我需要使用 CUDA C 编写并行应用程序。即使是最简单的示例也无法编译。我正在使用 Windows7 和 MS Visual Studio。代码取自书中:CUDA by example。通用 GPU 计算简介。

#include<iostream>
#include<cuda.h>

using namespace std;

__global__ void kernel(void){
}

int main(){
kernel<<<1, 1>>>();
cout << "Hello world" << endl;
return 0;
}

以下是错误:

1>c:\users\administrator\documents\visualstudio2010\projects\test\test\test.cpp(6): error C2144: syntax error : 'void' should be preceded by ';'
1>c:\users\administrator\documents\visualstudio2010\projects\test\test\test.cpp(6): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\administrator\documents\visualstudio2010\projects\test\test\test.cpp(10): error C2059: syntax error : '<'

是否需要将 nvcc.exe 设置为默认编译器而不是 cl.exe?如果是这样,该怎么做? 非常感谢任何帮助!

【问题讨论】:

    标签: c++ visual-studio-2010 cuda nvcc


    【解决方案1】:

    CUDA 代码需要写入.cu 文件并使用NVCC 编译器进行编译。您看到上述错误是因为您已在 .c.cpp 文件中编写代码并尝试使用 C++ 编译器(Visual C++ 编译器)对其进行编译。

    您选择了正确的书来学习 CUDA。但是,您并没有遵循书中给出的所有步骤。请查看书中编译的详细信息:-)

    【讨论】:

    • 谢谢...在将 test.cpp 重命名为 test.cu 后,CUDA C 确实编译了代码,但我认为它会创建 test.exe 文件而不是 a.exe!看来我一直在搜索错误的 .exe! -_- 谢谢阿什温的回复。
    • 如果您的 CUDA 源代码命名为 file.cu 并且您希望生成的文件命名为 file,则可以使用 NVCC 指定生成的可执行文件的名称.exe 试试这个命令nvcc file.cu -o file.exe。希望这会有所帮助。
    • @mmisu 是的......这有帮助。谢谢你的信息!在发布问题之前,我可能应该阅读 nvcc 手册。好吧,我希望永远不会太晚!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-26
    • 1970-01-01
    • 1970-01-01
    • 2020-11-13
    相关资源
    最近更新 更多