Hi all. I am porting a C program I wrote to C++. I am having some issues
with external variables. In C, I can have global variables declared in
common header files, but I get "multiple definition" errors when compiling as
c++. Here's an example:
/* BEGIN myhdr.h */
int GLOBAL_INT;
void func();
/* END myhdr.h */
/* BEGIN main.cpp */
#include"myhdr.h"
int main()
{
GLOBAL_INT = 1;
func();
return (0);
}
/* END main.cpp */
/* BEGIN func.cpp */
#include"myhdr.h"
void func()
{
GLOBAL_INT = 2;
}
/* END func.cpp */
g++ -c main.cpp
g++ -c func.cpp
g++ main.o func.o
func.o(.bss+0x0): multiple definition of `GLOBAL_INT'
main.o(.bss+0x0): first defined here
gmake: *** [test] Error 1
How can I get around this issue?
Thanks,
-Adam