2012-04-04 3 views
1

"링크 오류 LNK2005 ... 이미 정의 됨"오류로 몇 가지 문제점이 있습니다.링크 오류 LNK2005 여러 CUDA 파일

// File Bitmap8.cu 
#include "Bitmap8.h" // header 
#include "Bitmaps_cuda.h" // the same as above 

..... // I call 4 kernel functions (4 in the same method) 
다음

나는 커널 헤더가 :

:

#ifndef __BITMAPS_KERNEL__ 
#define __BITMAPS_KERNEL__ 

...... // 9 kernels definitions 

#endif 

그리고를 마지막으로, 나는이 하나가

다음
// File Bitmap4.cu 
#include "Bitmap4.h" // header 
#include "Bitmaps_cuda.h" // header with just the definitions of the kernels 

..... // I call 3+2 kernel functions (3 in one method, 1 in another and 1 in another one) 

나는 일이있다 : 다음과 같이 파일은

// File Bitmaps_cuda.h 
#include <cuda.h> 
#include <cuda_runtime.h> 
#include <device_launch_parameters.h> 
#include <device_functions.h> 
#include <stdio.h> 

// Inside here there all the kernel functions that the files 
// Bitmap4.cu and Bitmap8.cu are using 

문제는, 비트 맵 * .cu 중 하나에 #include "Bitmaps_cuda.h"을 포함 시키십시오. 물론 컴파일러는 커널 함수의 정의를 놓쳤다 고 말할 것입니다. 나는 많은 게시물을 읽었고 나는 이미 "추가의 직능들 (Dipendencies)"과 필요한 PATH를 포함했다. 문제는 상대적인 커널과 함께 Bitmap8.cu 파일을 추가했을 때 시작되었습니다. 그 전에는 응용 프로그램이 제대로 작동했기 때문입니다.

1>Bitmap8.cu.obj : error LNK2005: "void * __cdecl big_random_block(int([email protected]@[email protected]) already defined in Bitmap4.cu.obj 
1>Bitmap8.cu.obj : error LNK2005: "int * __cdecl big_random_block_int(int([email protected]@[email protected]) already defined in Bitmap4.cu.obj 
1>Bitmap8.cu.obj : error LNK2005: "unsigned char __cdecl value(float,float,int([email protected]@[email protected]) already defined in Bitmap4.cu.obj 
1>Bitmap8.cu.obj : error LNK2005: "void * __cdecl start_thread(unsigned int(__stdcall*)(void *),void *)" ([email protected]@[email protected]@Z) already defined in Bitmap4.cu.obj 
1>Bitmap8.cu.obj : error LNK2005: "void __cdecl end_thread(void *)"([email protected]@[email protected]) already defined in Bitmap4.cu.obj 
1>Bitmap8.cu.obj : error LNK2005: "void __cdecl destroy_thread(void *)"(?destroy[email protected]@[email protected]) already defined in Bitmap4.cu.obj 
1>Bitmap8.cu.obj : error LNK2005: "void __cdecl wait_for_threads(void * const *,int)"([email protected]@[email protected]) already defined in Bitmap4.cu.obj 
1>Bitmap8.cu.obj : error LNK2005: "void __cdecl__device_stub__Z14float_to_colorPhPKf(unsigned char *,float const *)"([email protected]@[email protected]) already defined in Bitmap4.cu.obj 
1>Bitmap8.cu.obj : error LNK2005: "void __cdecl float_to_color(unsigned char *,float_const *)" ([email protected]@[email protected]) already defined in Bitmap4.cu.obj 
1>Bitmap8.cu.obj : error LNK2005: "void __cdecl__device_stub__Z14float_to_colorP6uchar4PKf(struct uchar4 *,float const *)"([email protected]@[email protected]@[email protected]) already defined in Bitmap4.cu.obj 
1>Bitmap8.cu.obj : error LNK2005: "void __cdecl float_to_color(struct uchar4 *,float_const *)" ([email protected]@[email protected]@[email protected]) already defined in Bitmap4.cu.obj 

1>C:\Users\dberdin\documents\visual studio 2010\Projects\gpuSPAM\Debug\gpuSPAM.exe : fatal error LNK1169: one or more multiply defined symbols found 

내가 다른 솔루션을 시도했지만 어떤 결과 :

어쨌든, 사람들은 내가 가지고있는 오류입니다.

미리 감사드립니다. - 절대 각 정의에서 다른 값으로 두 번 정의된다
:

홈페이지 (http://msdn.microsoft.com/en-us/library/72zdcz6f.aspx)에서

EDIT 나 그 오류의 원인 중 하나 인 것으로 나타났다.
글쎄, 사실, 내가 바닥에 쓴 것처럼, 나는 이런 종류의 결정을하지만, 나는 다르게 할 수 없다. 어떤 아이디어로 그것을 해결할 수 있을까요? 당신이 9 개 커널 선언이 아니라 정의를 가지고

+0

헤더 파일을 두 번 포함했습니다. 문제 해결됨! – davideberdin

답변

2

파일을 두 번 포함하기 때문에 이러한 오류가 발생했습니다. 문제 해결됨!

1
Then I have the kernel header: 

#ifndef __BITMAPS_KERNEL__ 
#define __BITMAPS_KERNEL__ 

...... // 9 kernels definitions 

#endif 

당신이 말을하셨습니까 사전에 다시 한번 감사드립니다?

헤더 파일에 커널 정의를 사용할 수 없습니다.

모든 .cu 파일이 동일한 런타임에 링크되어 있는지 확인하십시오 (각 .cu 파일의 등록 정보 시트를 열고 CUDA C/C++ | Host | Runtime Library 설정을 비교하십시오.) 또한이 파일이 일반 cpp 파일에서 사용되는 것과 동일한 런타임인지 확인하십시오.

+0

헤더가 커널 헤더를 한 번만 가져오고, 장치 코드 컴파일 궤도를 통해 커널 정의가있는 것이 합법적입니다. Thrust와 같은 템플릿 라이브러리는 이러한 작업을 광범위하게 수행합니다. – talonmies

+0

"커널 정의를 헤더에 포함하는 것은 헤더가 한 번만 가져오고 장치 코드 컴파일 궤도를 통해 가져 오는 한 완전히 합법적입니다." 사실,하지만 정말로 헤더 파일을 가지고 있습니까?그것은 당신이 헤더 파일로 위장 된 구현 파일을 가지고 있기 때문에, 라인 아래로 혼란의 끝이 생기지 않을 것입니다. 템플리트 화 된 커널 정의는 예외가 될 것입니다. –

+0

글쎄, 로저 달 (Roger Dahl)의 해결책은 다른 문제를 해결하는 데 도움이되었지만 여전히 컴파일러는 내가 위에 게시 한 것과 같은 오류를주고 있습니다! 더 많은 커널 정의와 커널 기능을 추가 할 때 문제가 시작 되었기 때문에 나는 그것을 얻을 수 없습니다. 솔직히 말해서, 커널 함수의 일부는 내부의 일부 매개 변수를 제외하고는 동일한 연산을 수행하지만 여전히 컴파일 할 수없는 이상한 작업입니다. – davideberdin