Compiling and Linking help

Djekic Dusan djekic.dusan@gmail.com
Tue Nov 8 08:31:00 GMT 2005


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?



More information about the Gcc-help mailing list