Reputation: 3197
Pretty much forgot how to code C++ at all. Anyway, here is the problem.
I am trying to load a class defined in a .cpp file I wrote myself.
In the main function:
... ...
#include "loader.h"
... ...
model load_model("TechnologyEnterpriseFacility_Day_Gregor/
TechnologyEnterpriseFacility_Gregor.model");
the header file looks like this:
#ifndef LOADER_H_
#define LOADER_H_
class model
{
public:
int textures [];
float vertices[][3];
float triangles[][13];
model(const char*); // constructor
};
#endif /* LOADER_H_ */
and here is the .cpp file:
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <typeinfo>
#include "loader.h"
using namespace std;
model::model(const char* filename)
{
... ...
When I compile the main function, I got error message:
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
comments and ideas are welcomed, thanks.
Upvotes: 1
Views: 167
Reputation: 15
You need to supply the implementation file along with the header file. Either directly import it into your main program:
#include "implementation.cpp";
Or compile it separately with the compiler:
myCompiler -flags main.cpp implement.cpp
Either would work, but the latter is more maintainable and professional.
Upvotes: 0
Reputation: 6137
Didn't you forget to insert model.cpp
in your compilation line ?
gcc -o glrender glrender.cpp model.cpp -lglut
Upvotes: 3