The problem is that main.cpp included B.cpp and A.cpp . During the build process, you also compile B.cpp and A.cpp and try to bundle Bo and Ao together with main.o
Binding Bo and Ao calls several characters for the display and square characters. display defined 3 times, and square is 2 times.
You just compile and create main.cpp . Do not build A.cpp and B.cpp .
The second way is to make A.cpp and B.cpp before Ah and Bh and inline functions. Thus, they will be compiled only once.
Third , do not include B.cpp in main.cpp . Just put a function declaration instead of including it.
//main.cpp void square(int); int main() { square(5); return 0; }
Typically, function declarations are placed in header files. If this is required in several cases, create a header file.
source share