编译helloworld.cu时遇到问题 [英] Trouble compiling helloworld.cu

查看:162
本文介绍了编译helloworld.cu时遇到问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Ubuntu 10.10中编译此hello world示例

While compiling this hello world sample in Ubuntu 10.10

这是从 CUDA示例,第3章(未提供编译指令>:@)

This is from CUDA by Example, chapter 3 (No compile instructions provided >:@)

#include <iostream>

__global__ void kernel (void){


}

int main(void){

    kernel <<<1,1>>>();
        printf("Hellow World!\n");
    return 0;

}

我明白了:


$ nvcc -lcudart hello.cu hello.cu(11):错误:标识符 printf为
未定义

$ nvcc -lcudart hello.cu hello.cu(11): error: identifier "printf" is undefined


/tmp/tmpxft_00007812_00000000-4_hello.cpp1.ii的编译中检测到1个错误。

1 error detected in the compilation of "/tmp/tmpxft_00007812_00000000-4_hello.cpp1.ii".

为什么?

推荐答案

您需要包括 stdio.h cstdio 不是 iostream (用于 std :: cout 的东西)用于 printf (请参阅 man 3 printf )。我在此处。

You need to include stdio.h or cstdionot iostream (which is for std::cout stuff) for printf (see man 3 printf). I found the source code for the book here.

chapter03 / hello_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 README.txt file details how to compile the examples:



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

这篇关于编译helloworld.cu时遇到问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆