This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Compiling and Linking help
- From: Djekic Dusan <djekic dot dusan at gmail dot com>
- To: gcc-help at gcc dot gnu dot org
- Date: Tue, 8 Nov 2005 09:31:50 +0100
- Subject: Compiling and Linking help
Hello!
I have the the problem related to compiling and linking the following:
a.h
int a( ) { };
b.h
#include a.h
class B { B( ); };
b.cpp
#include "b.h"
B::B( ) { a( ); }
c.h
class C { C( ); };
c.cpp
#include "c.h"
C::C( ) { }
main.cpp
#include "b.h"
#include "c.h"
B b;
C c;
compiling: g++ -c b.cpp
g++ -c c.cpp
g++ -c main.cpp
linking: g++ -o out b.o c.o main.o
Here I get no compilation errors, but do get linking errors stating
multiple definitions of everything regarding a.h. I found out this is
the product of double compiling everything regarding a.h in b.o and
main.o, but could not find the way how to write proper and simple
Makefile, but to have object files for b, c and main, and afterwards
linked together. Could you help me with this?