So I am working on a rather large program using many .cpp files and ,h files and compiling them all together wit a Makefile.
I'm not the only one working on this project, and my part of it really comes down to just a few files. Here is a somewhat simplified version of the situation.
My source code files:
Basically, main calls functions from both foo.cpp and bar.cpp, and foo.cpp calls functions from bar.cpp.
In other word, foo depends on bar, and main depends on both.
The .h files contain function prototypes and definitions for their respective files.
I am using the Makefile to first create .o files for each of the .cpp programs, and then I am basically running
The result is a list of almost all of my functions and errors saying that I have defined them multiple times!Code:g++ main.o foo.o bar.o
What can I do to solve this problem?
By the way, foo.cpp has #includes for both headers and so does main.cpp. bar.cpp only includes bar.h.