Compiling and Linking help

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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?


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux