Проблемы с компиляцией helloworld.cu - PullRequest
7 голосов
/ 04 сентября 2011

При компиляции этого примера Hello World в Ubuntu 10.10

Это из CUDA по примеру , глава 3 (инструкции по компиляции не предоставляются>: @)

#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" равен не определен

1 ошибка обнаружена при компиляции «/tmp/tmpxft_00007812_00000000-4_hello.cpp1.ii".

Почему? Как этот код должен быть скомпилирован?

1 Ответ

11 голосов
/ 04 сентября 2011

Вы должны включить stdio.h, а не iostream (что для std::cout материала) для printf (см. man 3 printf). Я нашел исходный код для книги здесь .

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 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
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...