2011-03-08 9 views
0

Visual C++ 응용 프로그램에서 기존 클래스를 수정하여 제네릭 클래스로 만들었습니다. 이 클래스는 두 개의 다른 모듈에서 사용됩니다. 이 모듈을 따로 컴파일하면 모든 것이 작동합니다. 그러나 Build All을 수행하면 다음과 같은 링커 오류가 발생합니다.C++ 일반 클래스 링크 오류

1>Linking... 
1> Creating library C:\ccmdb\prep\g3_v5.3\g3_tools\fc_tools\ZFRTool\ZStackMTI\Debug\ZStackMTI.lib and object C:\ccmdb\prep\g3_v5.3\g3_tools\fc_tools\ZFRTool\ZStackMTI\Debug\ZStackMTI.exp 
1>SerialPort.obj : error LNK2019: unresolved external symbol "public: __thiscall CRingBuffer<unsigned char>::CRingBuffer<unsigned char>(unsigned long)" ([email protected]@@[email protected]@Z) referenced in function "public: __thiscall CSerialPort::CSerialPort(void)" ([email protected]@[email protected]) 
1>ZStackMTI.obj : error LNK2001: unresolved external symbol "public: __thiscall CRingBuffer<unsigned char>::CRingBuffer<unsigned char>(unsigned long)" ([email protected]@@[email protected]@Z) 
1>SerialPort.obj : error LNK2019: unresolved external symbol "public: __thiscall CRingBuffer<unsigned char>::~CRingBuffer<unsigned char>(void)" ([email protected]@@[email protected]) referenced in function "public: void * __thiscall CRingBuffer<unsigned char>::`scalar deleting destructor'(unsigned int)" ([email protected]@@[email protected]) 
1>ZStackMTI.obj : error LNK2001: unresolved external symbol "public: __thiscall CRingBuffer<unsigned char>::~CRingBuffer<unsigned char>(void)" ([email protected]@@[email protected]) 
1>SerialPort.obj : error LNK2019: unresolved external symbol "public: unsigned long __thiscall CRingBuffer<unsigned char>::GetBufferItems(void)" ([email protected][email protected]@@QAEKXZ) referenced in function "public: unsigned long __thiscall CSerialPort::GetBufferedRxItems(void)" ([email protected]@@QAEKXZ) 
1>SerialPort.obj : error LNK2019: unresolved external symbol "public: int __thiscall CRingBuffer<unsigned char>::Peek(unsigned char *,unsigned long,unsigned long *)" ([email protected][email protected]@@[email protected]) referenced in function "public: unsigned long __thiscall CSerialPort::Peek(unsigned char *,unsigned long,unsigned long *)" ([email protected]@@[email protected]) 
1>SerialPort.obj : error LNK2019: unresolved external symbol "public: int __thiscall CRingBuffer<unsigned char>::Remove(unsigned char *,unsigned long,unsigned long *)" ([email protected][email protected]@@[email protected]) referenced in function "public: unsigned long __thiscall CSerialPort::Read(unsigned char *,unsigned long,unsigned long *)" ([email protected]@@[email protected]) 
1>ZStackMTI.obj : error LNK2001: unresolved external symbol "public: int __thiscall CRingBuffer<unsigned char>::Remove(unsigned char *,unsigned long,unsigned long *)" ([email protected][email protected]@@[email protected]) 
1>SerialPort.obj : error LNK2019: unresolved external symbol "public: int __thiscall CRingBuffer<unsigned char>::Add(unsigned char *,unsigned long,int)" ([email protected][email protected]@@[email protected]) referenced in function "public: unsigned long __thiscall CSerialPort::Write(unsigned char *,unsigned long)" ([email protected]@@[email protected]) 
1>ZStackMTI.obj : error LNK2001: unresolved external symbol "public: int __thiscall CRingBuffer<unsigned char>::Add(unsigned char *,unsigned long,int)" ([email protected][email protected]@@[email protected]) 
1>SerialPort.obj : error LNK2019: unresolved external symbol "public: int __thiscall CRingBuffer<unsigned char>::Delete(unsigned long)" ([email protected][email protected]@@[email protected]) referenced in function "public: unsigned long __thiscall CSerialPort::Delete(unsigned long,int)" ([email protected]@@[email protected]) 
1>SerialPort.obj : error LNK2019: unresolved external symbol "public: int __thiscall CRingBuffer<unsigned char>::Flush(void)" ([email protected][email protected]@@QAEHXZ) referenced in function "public: unsigned long __thiscall CSerialPort::Flush(int)" ([email protected]@@[email protected]) 
1>ZStackMTI.obj : error LNK2019: unresolved external symbol "public: unsigned char __thiscall CRingBuffer<unsigned char>::Peek(unsigned long)" ([email protected][email protected]@@[email protected]) referenced in function "unsigned long __cdecl ZBNConnect_GetExtAddr(unsigned char *)" ([email protected]@[email protected]) 
1>C:\ccmdb\prep\g3_v5.3\g3_tools\fc_tools\ZFRTool\ZStackMTI\Debug\ZStackMTI.dll : fatal error LNK1120: 9 unresolved externals 
1>Build log was saved at "file://c:\ccmdb\prep\g3_v5.3\g3_tools\fc_tools\ZFRTool\ZStackMTI\ZStackMTI\Debug\BuildLog.htm" 
1>ZStackMTI - 14 error(s), 0 warning(s) 

Visual Studio 2008을 사용하고 있습니다.이 문제를 해결하는 방법을 알고 있습니까? 수정 이전에는 모든 것이 아무런 문제없이 구축되고 연결되었습니다. 감사.

+0

클래스 코드와 발신자 코드를 게시 할 수 있습니까? – Cosmin

답변

6

헤더 파일에 템플릿 함수를 구현하십시오.

컴파일러는 템플릿에서 실제 클래스을 만들 때 전체 클래스 템플릿을 참조 할 필요가있다. 예 : Why should the implementation and the declaration of a template class be in the same header file?

+0

어떻게 문제를 해결할 수 있습니까? –

+0

템플릿 클래스는 * 클래스가 아니며 * 템플릿 *입니다. 컴파일러가'Foo '을 사용하여 당신을 볼 때 그것은 템플릿 코드로부터 실제 클래스를 생성합니다. 컴파일러가이 클래스를 생성 할 때'Foo' 멤버 함수 * 선언 * 만 볼 수 있다면'Foo '멤버 함수 선언 만 생성합니다. 정의를 볼 수 있으면 정의를 작성합니다. – Erik

+0

템플릿 함수 정의를 잘라내어 템플릿 클래스가 정의 된 헤더 파일의 끝까지 지나쳐야합니까? 또는 실제로 클래스 내에서 중첩 될 필요가 있습니까? Java 또는 C# 클래스가 정의 된 것과 유사합니까? –

0

이것은 링커가 구체적인 클래스의 메서드 본문을 찾을 수 없기 때문일 수 있습니다.

한 가지 해결 방법은 템플릿 기반 클래스의 구체적인 인스턴스를 선언 할 때 .h 파일 대신 실제 .cpp 파일을 포함시키는 것입니다.

+0

해결 방법을 보내 주셔서 감사합니다. 나는 그것을 명심해야한다. –