multiple definitions error

Hello everyone,

I started coding c/c++ yesterday and I've been having tons of fun! Unfortunately, I've come across an error that I can't fix no matter what I try.

I'm trying to build a shell-like environment (like when you type the command 'openssl' it takes to you the openssl shell) but I'm getting compiling errors saying this:

**** Build of configuration Debug for project JoHttpd ****

make all 
Building file: ../src/JoHttpd.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/JoHttpd.d" -MT"src/JoHttpd.d" -o "src/JoHttpd.o" "../src/JoHttpd.cpp"
Finished building: ../src/JoHttpd.cpp
 
Building file: ../src/ShellCommandExecutors.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/ShellCommandExecutors.d" -MT"src/ShellCommandExecutors.d" -o "src/ShellCommandExecutors.o" "../src/ShellCommandExecutors.cpp"
Finished building: ../src/ShellCommandExecutors.cpp
 
Building target: JoHttpd
Invoking: GCC C++ Linker
g++  -o "JoHttpd"  ./src/JoHttpd.o ./src/ShellCommandExecutors.o ./src/ShellCommandHandler.o ./src/ShellEnviroment.o   
./src/ShellCommandExecutors.o: In function `ShellCommandExecutors::exitBash()':
/home/john/workspace/JoHttpd/Debug/../src/ShellCommandExecutors.cpp:35: multiple definition of `ShellENV'
./src/JoHttpd.o:/home/john/workspace/JoHttpd/Debug/../src/JoHttpd.cpp:37: first defined here
collect2: ld returned 1 exit status
make: *** [JoHttpd] Error 1

**** Build Finished ****


I'm assuming it's some sort of inheritance problem when I declare 'ShellEnviroment' to the variable 'ShellENV' on line 32 of 'ShellCommandExecutor.cpp' and line 33 of 'JoHTTPd.cpp. If anyone can give me an explanation to this error and posibly a fix, I would be ever so gratefull. Thanks!

Source Code: http://www.mediafire.com/?buq4qv2z01px1vi
¿inheritance?
The problem is that you've got 2 different variables with the same name at the same scope.

If you wanted for the variable to be shared use extern
If you want for each unit to hold its own copy, use static or unnamed namespace
Okay, that fixed it. Thank you, ne555.
Topic archived. No new replies allowed.