2010-12-08 2 views
1

나는 간단한 게임 엔진을 쓰고 있어요 연결을 찾을 수 없습니다, 그리고 나는 EntityComponent.h 파일이 있습니다기호 라이브러리

#include "EntityComponent.h" 
#include <string> 

psycho2d::EntityComponent::EntityComponent(const std::string &name){ 
    this->m_name = name; 
} 

psycho2d::EntityComponent::~EntityComponent(){} 

inline const std::string& psycho2d::EntityComponent::getName() const{ 
    return this->m_name; 
} 

이를 :

#ifndef Psycho2D_Core_EntityComponent_ 
#define Psycho2D_Core_EntityComponent_ 

#include <string> 

namespace psycho2d{ 

    class EntityComponent{ 

    private: 
     std::string m_name; 

    public: 
     EntityComponent(const std::string &name); 

     virtual ~EntityComponent(); 

     const std::string& getName() const; 

     virtual void initialize() = 0; 

     virtual void loadProperties() = 0;  

     virtual void update() = 0; 

     virtual void destroy() = 0; 

    }; 

} 

#endif 

그리고 상대 EntityComponent.cpp 파일을 두 파일은 프레임 워크의 일부입니다 (저는 Mac에서 작업 중입니다). 그들은 잘 컴파일됩니다. 문제는 라이브러리를 사용하는 실행 파일을 작성할 때입니다. EntityComponent의 하위 클래스를 만들고 컴파일했습니다. 나는 getName() 함수를 호출한다면, 링커는 말해 :

"psycho2d::EntityComponent::getName() const", referenced from: 
_main in main.o 
Symbol(s) not found 
Collect2: ld returned 1 exit status 

내가 할 수있는 무엇? 감사합니다. .

+0

지정 구현 된 적이 있습니까? –

+1

컴파일/링크 명령을 포함하면 도움이 될 수 있습니다. –

답변

3

여러 .cpp 파일에서 인라인 함수를 참조하려는 경우 인라인 함수의 코드를 헤더 파일에 넣습니다.

참조 here.

+0

감사합니다;) – Sigel

0

귀하의 코드가 내 컴퓨터에 잘 컴파일 (약간 텍스트 서브 클래스를 포함하도록 수정) (A 맥, 너무. GCC 4.2.1)

모든 .o 인-파일을 제거 시도하고 클린 디렉터리로 컴파일합니다. 그것도 실패한다면, 나는 인라인 정의를 제거하려고합니다.

0

구현에서 inline 한정자를 제거해보십시오.

2

외부 링크 inline 함수는 사용되는 모든 번역 단위에서 정의되어야합니다 (사실상 동일 함).

따라서 정의에서 inline을 제거하거나 정의를 헤더 파일에 배치하십시오.

건배 & HTH., 당신은 추상적 가상 메서드의 모든 당신이 당신의 인터페이스에

+0

이유를 설명하는 +1 –