Skip to content
Advertisement

Undefined references in makefile

Ok, ive read about 10 tutorials, but i keep getting errors all the time, i have 5 files, main.cpp class.cpp, class.h and functions.cpp and functions.h. All of those use functions from different objects meaning that functions in functions.cpp uses objects from classes.cpp.

My makefile looks as follows

JavaScript

I keeps telling me that it has undefined references. What am i missing?

What makefile outputs

JavaScript

The files compile great when i had them in Visual C++, so it has to be my makefile.

Advertisement

Answer

You are indeed doing something strange. What you should is to compile (-c) the object files and then link them together. This would look like this:

JavaScript

While you are doing this, it is even better if you compiled main.o separately also. Therefore:

JavaScript

Also note that I removed the $(LIBS) when using -c because linking doesn’t happen then.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement