helloWorld - linker error - gelöst

Beiträge: 144
Registriert: 9. Mai 2006 22:01
Wohnort: Mainz

helloWorld - linker error - gelöst

Beitrag von ykaerflila »


zur erinnerung der code aus der vorlesung


Code: Alles auswählen

#include <cutil.h>	// various definitions, macros, ...
#include <helloWorld_kernel.cu>						// include the code actually executed on the GPU

#define BLOCK_SIZE 16
#define GW (5 * BLOCK_SIZE)							// defining constants

int main(int argc, char** argv) {					// the main program
   CUT_DEVICE_INIT();								// select the device for computation
   printf("block size: %u \n", BLOCK_SIZE);			// debug output on host
   printf("grid dimension: %u\n", GW/BLOCK_SIZE);
   dim3 threads(BLOCK_SIZE);						// number of threads per block
   dim3 grid(GW / BLOCK_SIZE);						// number of blocks in grid
   helloWorld<<< grid, threads >>>();				// start kernel (executed on the device)
   CUT_CHECK_ERROR("Kernel execution failed");		// check for success


Code: Alles auswählen

// NOTE: This kernel will only compile in emulation mode.
// Devices do not support "printf" statements!
#ifndef _HELLOWORLD_KERNEL_CU_										// avoid multiple reads and interpretation of file

	#include <stdio.h>													// only required for printf()
	__global__ void helloWorld() {										// definition of a global function, callable from host
	    if ( blockIdx.x==0 && threadIdx.x==0) {							// executed only once
	    printf("Welcome to the Hello World test program for CUDA.\n");	// welcome message
	  // output per thread
	  printf("Hello World!\n");											// print message per thread
	  printf("Block index: x: %u \n", blockIdx.x);						// print block ID and thread ID (in block)
	  printf("Thread index: x: %u\n", threadIdx.x);

#endif // #ifndef _HELLOWORLD_KERNEL_CU_
compiler läuft durch aber es kommt folgender linker-fehler:

Code: Alles auswählen

helloWorld_kernel.o: In function `helloWorld()':
tmpxft_00001631_00000000-3.i:(.text+0x745c): multiple definition of `helloWorld()'
helloWorld.o:tmpxft_00001620_00000000-3.i:(.text+0x7514): first defined here
helloWorld_kernel.o: In function `__device_stub__Z10helloWorldv':
tmpxft_00001631_00000000-3.i:(.text+0x7483): multiple definition of `__device_stub__Z10helloWorldv'
helloWorld.o:tmpxft_00001620_00000000-3.i:(.text+0x753b): first defined here
collect2: ld returned 1 exit status
was mache ich falsch?

edit: mit einem extra header-file gehts.
icq# 117752728
email: 7pinacoladas@gmx.net

Zurück zu „Archiv“