2010-01-24 4 views
1

C++ 코딩 방법을 거의 잊어 버렸습니다. 어쨌든, 여기에 문제가 있습니다.C++ 컴파일 문제

내가 작성한 .cpp 파일에 정의 된 클래스를로드하려고합니다. 메인 함수에서

:

... ... 
#include "loader.h" 
... ... 
model load_model("TechnologyEnterpriseFacility_Day_Gregor/ 
       TechnologyEnterpriseFacility_Gregor.model"); 

헤더 파일은 다음과 같습니다

#ifndef LOADER_H_ 
#define LOADER_H_ 

class model 
{ 
    public: 
    int textures []; 
    float vertices[][3]; 
    float triangles[][13]; 
    model(const char*); // constructor 
}; 

#endif /* LOADER_H_ */ 

을 여기 .cpp 파일입니다 : 내가 메인 컴파일 할 때

#include <iostream> 
#include <fstream> 
#include <string> 
#include <sstream> 
#include <typeinfo> 
#include "loader.h" 

using namespace std; 

model::model(const char* filename) 
{ 
    ... ... 

함수에 오류 메시지가 표시됩니다.

gcc -o glrender glrender.cpp -lglut 
/tmp/cc3sWIgb.o: In function `__static_initialization_and_destruction_0(int, int)': 
glrender.cpp:(.text+0x11b): undefined reference to `model::model(char const*)' 
collect2: ld returned 1 exit status 

의견과 아이디어를 환영합니다. 감사합니다.

+0

주요 기능은 클래스를 구현하는 cpp 파일과 같은 파일에 있습니까? – Javier

답변

3

컴파일 라인에 model.cpp을 삽입하는 것을 잊지 않았습니까?

gcc -o glrender glrender.cpp model.cpp -lglut 
+0

오, 이런, 나는 녹슨 ... 감사합니다. –

0

헤더 파일과 함께 구현 파일을 제공해야합니다.

#include "implementation.cpp"; 

또는 컴파일러와 별도로 컴파일 : 직접 메인 프로그램으로 가져

myCompiler -flags main.cpp implement.cpp 

중 하나가 작동 것이지만, 후자는 더 유지 보수 및 전문입니다.