B
Bram Kuijper
Hi all,
I am having a classical 'multiple definition error' of a global
variable, but this time I cannot find a good explanation of how to
prevent this multiple definition error.
I defined a global variable, needed by some functions, inside a header
file with ifndef clauses in order to prevent multiple definition:
#ifndef _MYRANDOM_H_
#define _MYRANDOM_H_
long int idum;
long int idum2;
// some function declarations etc
#endif
// end of header file
The functions declared in this header file are put in a static library.
Subsequently, this static library is used by a number of other static
libraries. Compiling these static libraries does not yield any errors.
Next to that I compile a program using those static libraries and
subsequently the errors surface. Errors like:
/home/bram/Varsity/C++/Simulation_classes/Trait/express.cpp:48: multiple
definition of `idum'
/tmp/cciYexgh.o:/home/bram/Varsity/genconfl/haplodiploidy/spatial/main.cpp:14:
first defined here
/home/bram/lib/libtrait.a(express.o): In function
`__static_initialization_and_destruction_0':
/home/bram/Varsity/C++/Simulation_classes/Trait/express.cpp:48: multiple
definition of `idum2'
/tmp/cciYexgh.o:/home/bram/Varsity/genconfl/haplodiploidy/spatial/main.cpp:14:
first defined here
/home/bram/lib/libtrait.a(inherit.o): In function
`__static_initialization_and_destruction_0':
/home/bram/include/gene.h:55: multiple definition of `idum'
How can it be that when I use this header file, the variables are
redefined _despite_ me using #ifndef clauses? I am using g++ 4.1.3 on a
ubuntu linux box and I did not define any of those variables outside the
header file.
thanks in advance,
Bram
I am having a classical 'multiple definition error' of a global
variable, but this time I cannot find a good explanation of how to
prevent this multiple definition error.
I defined a global variable, needed by some functions, inside a header
file with ifndef clauses in order to prevent multiple definition:
#ifndef _MYRANDOM_H_
#define _MYRANDOM_H_
long int idum;
long int idum2;
// some function declarations etc
#endif
// end of header file
The functions declared in this header file are put in a static library.
Subsequently, this static library is used by a number of other static
libraries. Compiling these static libraries does not yield any errors.
Next to that I compile a program using those static libraries and
subsequently the errors surface. Errors like:
/home/bram/Varsity/C++/Simulation_classes/Trait/express.cpp:48: multiple
definition of `idum'
/tmp/cciYexgh.o:/home/bram/Varsity/genconfl/haplodiploidy/spatial/main.cpp:14:
first defined here
/home/bram/lib/libtrait.a(express.o): In function
`__static_initialization_and_destruction_0':
/home/bram/Varsity/C++/Simulation_classes/Trait/express.cpp:48: multiple
definition of `idum2'
/tmp/cciYexgh.o:/home/bram/Varsity/genconfl/haplodiploidy/spatial/main.cpp:14:
first defined here
/home/bram/lib/libtrait.a(inherit.o): In function
`__static_initialization_and_destruction_0':
/home/bram/include/gene.h:55: multiple definition of `idum'
How can it be that when I use this header file, the variables are
redefined _despite_ me using #ifndef clauses? I am using g++ 4.1.3 on a
ubuntu linux box and I did not define any of those variables outside the
header file.
thanks in advance,
Bram