Cuda 编译helloworld.cu时遇到问题
在Ubuntu 10.10中编译这个hello world示例时 这来自第3章(未提供编译说明>:@)Cuda 编译helloworld.cu时遇到问题,cuda,Cuda,在Ubuntu 10.10中编译这个hello world示例时 这来自第3章(未提供编译说明>:@) #包括 __全局无效内核(void){ } 内部主(空){ 内核(); printf(“Hellow World!\n”); 返回0; } 我明白了: $nvcc-lcudart hello.cu hello.cu(11):错误:标识符“printf”为 未定义 在编译过程中检测到1个错误 “/tmp/tmpxft_00007812_u00000000-4_hello.cpp1.ii” 为什
#包括
__全局无效内核(void){
}
内部主(空){
内核();
printf(“Hellow World!\n”);
返回0;
}
我明白了:
$nvcc-lcudart hello.cu hello.cu(11):错误:标识符“printf”为
未定义
在编译过程中检测到1个错误
“/tmp/tmpxft_00007812_u00000000-4_hello.cpp1.ii”
为什么??这个代码应该如何编译?你需要在
printf
中包含stdio.h
或cstdio
而不是iostream
(这是用于std::cout
的东西)(请参见man 3 printf
)。我找到了这本书的源代码
chapter03/hello\u world.cu
实际上是:
/*
* Copyright 1993-2010 NVIDIA Corporation. All rights reserved.
*
* NVIDIA Corporation and its licensors retain all intellectual property and
* proprietary rights in and to this software and related documentation.
* Any use, reproduction, disclosure, or distribution of this software
* and related documentation without an express license agreement from
* NVIDIA Corporation is strictly prohibited.
*
* Please refer to the applicable NVIDIA end user license agreement (EULA)
* associated with this source code for terms and conditions that govern
* your use of this NVIDIA software.
*
*/
#include "../common/book.h"
int main( void ) {
printf( "Hello, World!\n" );
return 0;
}
其中。/common/book.h
包括stdio.h
README.txt
文件详细介绍了如何编译示例:
The vast majority of these code examples can be compiled quite easily by using
NVIDIA's CUDA compiler driver, nvcc. To compile a typical example, say
"example.cu," you will simply need to execute:
> nvcc example.cu
通过使用
NVIDIA的CUDA编译器驱动程序,nvcc。要编译一个典型的例子,比如
“example.cu”,您只需执行:
>nvcc example.cu
问题是编译器不知道在哪里可以找到
printf
函数。信息技术
需要知道在哪里找到它。include
指令用于告诉编译器在哪里可以找到它
#包括“stdio.h”
内部主(空){
printf(“你好,世界!\n”);
返回0;
}
修复后,它将工作:
$nvcc hello\u world.cu
$ls
a、 走出hello_world.cu
一美元
你好,世界!
@awoodland:Hmmmm,第二个答案是这样的,事实上第B14节有“printf”(“Hello thread%d,f=%f\n”,threadIdx.x,f);“那么应该如何编译它呢?如果我没记错的话,那本书中的代码只是片段,并不总是完整的示例。更不用说他们在这些例子中使用了“糟糕的练习”的alto…我发布了第二个示例,来自第3.2.2节的“逐字逐句”,其中确实包含@omgzor:这是一个错误。检查该书(从我的答案中链接的页面)。”p、 23,25-本例中的#include错误显示为:#include和#include“book.h”。这已在可下载的代码包中更正,但应改为:#include和#include”。/common/book.h“。(您可能正在查看chapter03/simple\u kernel.cu
的代码,而不是chapter03/hello\u world.cu
)谢谢,我没有检查这本书的代码,因为我的pdf没有提到它是可用的。答案中提供的链接现在已断开。这里有一个替代链接,可能对某些人有用。
The vast majority of these code examples can be compiled quite easily by using
NVIDIA's CUDA compiler driver, nvcc. To compile a typical example, say
"example.cu," you will simply need to execute:
> nvcc example.cu