2011-10-16 2 views
0

=)C++에서 "undefined refence to"에 대해

C++에서 "정의되지 않은 참조"에 대한 질문이 있습니다.

다음은이 코드에서 나는 다음이 : 또 다른 C++ 파일에서

#include "HelloWorldAgent/helloworldagent.hh" 

int main() 
{ 
    HelloWorldAgent agent; 
    agent.run(); 
} 

다음 코드입니다 : 나는 g ++

함께 컴파일하려고

#ifndef _HELLOWORLDAGENT_HH_ 
#define _HELLOWORLDAGENT_HH_ 

#include "../../HumanoidAgent/humanoidagent.hh" 

/** 
* A friendly robot 
*/ 
class HelloWorldAgent : public bats::HumanoidAgent 
{ 
/** 
* Initialize agent 
* 
* Called a single time when starting up the agent. Put all your initialization stuff 
here. 
*/ 
virtual void init(); 

/** 
* Think cycle 
* 
* Called at each cycle after a message from the server is received and parsed. 
Put all your thinking and acting stuff here. 
*/ 
virtual void think(); 

public: 

/** 
* The Constructor 
* 
* Sets this agent's teamname to "Hello". Consider putting initialization stuff in 
init() instead of here. 
*/ 
HelloWorldAgent() 
: HumanoidAgent(std::string("Hello")) 
{ 
} 

}; 

#endif 

$ g ++ - I/usr/include/eigen -I /usr/include/sigc++-2.0 -I /usr/lib/sigc++-2.0/include helloworld.cc

그리고

파일에서 /usr/lib/gcc/i486-slackware-linux/4.5.2/../../../../include/c++/4.5.2에 포함되어 있습니다./ext/hash_map : 60 : 0, from HelloWorldAgent /../../ HumanoidAgent /../ WorldModel /../ Hashclasses/hashclasses.hh : 25, from HelloWorldAgent /../../ 휴머노이드 에이전트 /. ./WorldModel/worldmodel.hh:54, from HelloWorldAgent /../../ HumanoidAgent/humanoidagent.hh : 46, from HelloWorldAgent/helloworldagent.hh : 44, helloworld.cc에서 : 1 : /usr/lib/gcc/i486-slackware-linux/4.5.2 /../../../../ include/C++/4.5.2/backward/backward_warning.h : 28 : 2 : 경고 : #warning이 파일 futur에서 추후 통지없이 제거 될 수있는 적어도 하나의 비추천 또는 구식 헤더 포함 날짜. 동일한 기능을 가진 비 비추천 인터페이스를 대신 사용하십시오. 대체 헤더 및 인터페이스 목록은 backward_warning.h 파일을 참조하십시오. 이 경고를 사용하지 않으려면 -Wno-deprecated를 사용하십시오. /tmp/cc1cjIEs.o : 기능에서 main': helloworld.cc:(.text+0x29): undefined reference to 박쥐 :: HumanoidAgent :: 실행() ' /tmp/cc1cjIEs.o : HelloWorldAgent에 대한 기능 HelloWorldAgent::HelloWorldAgent()': helloworld.cc:(.text._ZN15HelloWorldAgentC2Ev[_ZN15HelloWorldAgentC5Ev]+0xfd): undefined reference to의 vtable에서' /tmp/cc1cjIEs.o : HelloWorldAgent에 대한 기능 HelloWorldAgent::~HelloWorldAgent()': helloworld.cc:(.text._ZN15HelloWorldAgentD2Ev[_ZN15HelloWorldAgentD5Ev]+0xb): undefined reference to의 vtable에서 ' collect2 : ld가 1 개의 종료 상태를 반환했습니다.

나는 무엇이 될 수 있는지 모르지만 어쩌면 내가 잘못하고 있습니다. 어떤 아이디어?

미리 감사드립니다. =)

PS : 아니, 당신은 HelloWorldAgent에서 가상 기능 구현 (정의)를 포함하지 않은)

+0

가능한 중복 [링크 오류 : 'vtable for XXX'에 대한 정의되지 않은 참조] (http://stackoverflow.com/questions/7720205/linking-error-undefined-reference-to-vtable-for-xxx) – bdonlan

답변

1

= 그냥 재미있다, 숙제를하지 않습니다. G ++에 이러한 정의가있는 파일을 모두 전달하고 (또는 을 사용하여 한 번에 하나씩 파일을 .o 개 파일로 컴파일 한 다음 최종 링크 단계에서 함께 연결하십시오)

+0

감사합니다. 이것은 도움이되었다. =) –

0

가장 간단한 방법은 이 문제를 해결하려면 g ++ 명령 줄에서 HelloWorldAgent 클래스에 선언 된 메서드의 실제 정의가있는 .cc 파일을 포함해야합니다. 호출하는 것처럼 보이는 유일한 방법은 run()이기 때문에이 파일을 .cc 파일의 어딘가에 정의해야합니다.

+0

당신이 그 대답을 좋아한다면 upvote에 망설이지 말고 :-) – chetan