undefined reference

Dec 30, 2010 at 5:36pm
I know there are several other posts about this issue, but none of the ones I can find have been helpful.

I'm trying for the first time to compile a fairly large codebase. Everything compiles fine except for two classes. This is an example of the compiler-error I get:


/tmp/ccZfRwyv.o: In function `GeometricObject::GeometricObject()':
GeometricObject.cpp:(.text+0x34): undefined reference to `RGBColor::RGBColor(float, float, float)'


The GeometricObject.h includes RGBColor.h, and GeometricObject has an instance of RGBColor, but none of the rest of the code references RGBColor. The RGBColor constructor mentioned in the error is defined:

 
RGBColor(const float nr, const float ng, const float nb);


and declared:

1
2
RGBColor::RGBColor(const float nr, const float ng, const float nb) : r(nr), g(ng), b(nb) {
}


As far as I can see, there is nothing wrong with either implementation or definition. Any clues?

Peace
Dec 30, 2010 at 5:40pm
If you have multiple source files, make sure you are linking every object file you need into the final binary
Dec 30, 2010 at 5:47pm
Yep, all the files are there. When I first encountered the issue, I realized that I HAD forgotten to include RGBColor when compiling, but now I have fixed that and the issue still remains.
Dec 30, 2010 at 6:15pm
what about linking?
Dec 30, 2010 at 6:22pm
I use: g++ foo1.cpp foo2.cpp foo3.cpp -o foo -lm
Dec 30, 2010 at 7:12pm
No IDE?
Dec 30, 2010 at 7:16pm
No, I'm only using gedit and g++ in terminal. I'm currently using a netbook, so I need as much screen real-estate as possible for the actual code. I find all the IDEs I've tried to clutter up my screen:p If you have a suggestion for a good IDE for netbook usage, I'd be grateful:)
Dec 30, 2010 at 7:55pm
Ok, I moved RGBColor to the beginning of the list of files in the g++ command, and now it appears to work. Does that make sense?
Dec 31, 2010 at 3:48am
Dunno. If that is really an issue, compile like
g++ *.cpp -c #just compile, don't link
g++ *.o -o program.bin
Topic archived. No new replies allowed.