Results 1 to 2 of 2
I am writing a multifile program. However I am having trouble when getting everything linked together with gcc. I am writing in C and using some libraries from C++
I ...
- 04-27-2007 #1Just Joined!
- Join Date
- Jan 2006
- Posts
- 15
Headerfile Hell
I am writing a multifile program. However I am having trouble when getting everything linked together with gcc. I am writing in C and using some libraries from C++
I have divided each unit of functionality into a directory with its headerfile. I have about 10 .cpp files and their header files. I have enclosed a snapshot of what I have at the moment:
an example Main.cpp
===================
#include "Initialize/Initialize.h"
#include "Support/Support.h"
#include "RNG/RNG.h"
etc etc....
=======================
an example Initialize.cpp
=======================
#include "Initialize.h"
=======================
and Initialize.h
========================
#ifndef _Initialize_h
#define _Initialize_h
#include "../RNG/RNG.h"
void ..
void ...
void ...
#endif
========================
Now the problem is get is the following on compiling and linking....
g++ -O5 -o Sim FileHandling/FileHandling.o Stress/Stress.o MonteCarlo/MonteCarlo.o COM/COM.o Support/Support.o DataStructures/DataStructures.o Diffusion/Diffusion.o Vectors/Vectors.o Energy/Energy.o RNG/RNG.o Support/Support.o Differential/Differential.o Main.o
Support/Support.o(.text+0x0): In function `BoltzmannWeight(double)':
: multiple definition of `BoltzmannWeight(double)'
Support/Support.o(.text+0x0): first defined here
Support/Support.o(.text+0x10): In function `free_2d(double**, int, int)':
: multiple definition of `free_2d(double**, int, int)'
Support/Support.o(.text+0x10): first defined here
Support/Support.o(.text+0x70): In function `free_2dint(int**, int, int)':
: multiple definition of `free_2dint(int**, int, int)'
Support/Support.o(.text+0x70): first defined here
Support/Support.o(.text+0xd0): In function `CalcAreaDisp(double, double, double)':
: multiple definition of `CalcAreaDisp(double, double, double)'
Support/Support.o(.text+0xd0): first defined here
Support/Support.o(.text+0x100): In function `CopyToBeadArray(double (*) [3], double***, int)':
: multiple definition of `CopyToBeadArray(double (*) [3], double***, int)'
Support/Support.o(.text+0x100): first defined here
Support/Support.o(.text+0x130): In function `DisplacementR(int, double, double, double, double***, double&, double&, double&, double, double, double)':
: multiple definition of `DisplacementR(int, double, double, double, double***, double&, double&, double&, double, double, double)'
Support/Support.o(.text+0x130): first defined here
Support/Support.o(.text+0x190): In function `DisplaceBeadSimple(double (*) [3], double, double, double, double)':
: multiple definition of `DisplaceBeadSimple(double (*) [3], double, double, double, double)'
Support/Support.o(.text+0x190): first defined here
Support/Support.o(.text+0x200): In function `DisplaceBeadTest(double (*) [3], double)':
: multiple definition of `DisplaceBeadTest(double (*) [3], double)'
Support/Support.o(.text+0x200): first defined here
Support/Support.o(.text+0x230): In function `ExtractBead(double (*) [3], int, double***)':
: multiple definition of `ExtractBead(double (*) [3], int, double***)'
Support/Support.o(.text+0x230): first defined here
================================================== ===========
The Make file is like:
all: Sim
Sim: FileHandling/FileHandling.o Stress/Stress.o MonteCarlo/MonteCarlo.o COM/COM.o Support/Support.o DataStructures/DataStructures.o Diffusion/Diffusion.o Vectors/Vectors.o Energy/Energy.o RNG/RNG.o Support/Support.o Differential/Differential.o Main.o
g++ -O5 -o Sim FileHandling/FileHandling.o Stress/Stress.o MonteCarlo/MonteCarlo.o COM/COM.o Support/Support.o DataStructures/DataStructures.o Diffusion/Diffusion.o Vectors/Vectors.o Energy/Energy.o RNG/RNG.o Support/Support.o Differential/Differential.o Main.o
Vectors/Vectors.o: Vectors/Vectors.cpp
g++ -O5 -c -Wno-deprecated -Wall Vectors/Vectors.cpp -o Vectors/Vectors.o
================================================== ==============
My question is thus.....
How best can I integrate and include these headerfiles. I seem not be including anything twice and therefore cannot see where I am getting the link error from. Is there a smarter way of doing it rather than the current way that would avoid this error?
Thanks
- 04-28-2007 #2Linux User
- Join Date
- Oct 2004
- Location
- /dev/random
- Posts
- 404
Need to take a look at the code organization.
Can you please attach the zip file containing all the code?
The linker errors generally mean that the symbol table generated by the compiler is messed up - it is not able to resolve symbols or finds multiple instances of the same symbol (which is happening in your case).
We need to see the code to understand why is this happening.The Unforgiven
Registered Linux User #358564


Reply With Quote