multiple definition error with namespace in .h file

Started by
13 comments, last by c0uchm0nster 14 years, 11 months ago
Hey I have a library that I made with about 12 .h and .cpp files. This is switchmaster.h:

#ifndef SWITCHMASTER
#define SWITCHMASTER

//day is x cycles long  (x milliseconds on fast machine)
#define DAYLEN 1800000
//x cycles to shift daylight
#define DAYSHIFT 2000.0f
#define CLOUDSHIFT 2000.0f

#define HORZ 1024
#define VERT 768
#define BPP 32

//max length of a filename this program will work with (exluding extension, I think so really IFILE+4)
#define IFILE 10
//half the size of the hero you want to draw, make this obsolete eventually
#define IHEROHALF 58
#define DVAL 800

//#define RATSLAM 3
//#define RATDAMAGE 0.5f

//the number of defined gizmo types -1
//0 = standard player gizmo | NO AI     | 32 PNG's, 1 GIZ
//1 = rat gizmo             | SIMPLE AI | 16 PNG's
//2 = simple mill           | SPIN      | 3 PNG's
//3 = stain                 |           | 4 PNG's
#define IGIZ 3
//number of defined anibox types -1
#define IANI 0
//the number of different possible layers -1
#define ILAYER 4

#define SCROLLSPEED 16.0f


//should only be three sections this effects
#define PROGRAMMER
//#define VAULTCHECK

namespace FileLocations
{
  std::string Anibox_Path;    //"Data/Anibox/";
  std::string Gizmo_Path;     //"Data/Gizmos/";
  std::string Image_Path;     //="Data/Images/";
  std::string Map_Path;       //="Data/Maps/";
  std::string Song_Path;      //="Data/Songs/";
  std::string Sound_Path;     //="Data/Sounds/";
}

#endif





switchmaster.h has all my #defines in it and stuff like that. My basic dependencies go like this: MapBox.h -> Gizbox.h -> Gizmo.h ->TexBox.h -> Picloader.h Where everything is dependent on the existence of Picloader.h Gizmo.h is also dependent on switchmaster.h so that is the only file that #includes it. I have a whole other separate project that includes this library. I compile this library, then I compile the other project. Now I decided to add that namespace at the bottom of switchmaster.h. I can't link anymore, I get this mess:

cd '/home/icecube/project5/debug/./src/editor' && WANT_AUTOCONF_2_5="1" WANT_AUTOMAKE_1_6="1" LC_MESSAGES="C" LC_CTYPE="C" gmake pr5edit
/bin/sh ../../libtool --tag=CXX --mode=link g++ -O0 -g3 -lGL -lSDL_mixer
-lGLU -lSDL_image -o pr5edit ice_edit.o keydown.o keygrabber.o mouseclick.o
movemouse.o navigate.o paintblocks.o paintfade.o paintgiz.o painthero.o
paintmap.o paintmaster.o paintmenu.o pr5edit.o superupdate.o ../../src/shared
/libicelibrary.a 
g++ -O0 -g3 -o pr5edit ice_edit.o keydown.o keygrabber.o mouseclick.o
movemouse.o navigate.o paintblocks.o paintfade.o paintgiz.o painthero.o
paintmap.o paintmaster.o paintmenu.o pr5edit.o superupdate.o /usr/lib/libGL.so
-L/usr/X11R6/lib /usr/lib/libSDL_mixer.so -L/usr/lib -lGLU /usr/lib
/libSDL_image.so -lpng /usr/lib/libtiff.so -ljpeg -lc -lz /usr/lib/libSDL.so
-lm /usr/lib/libXrandr.so /usr/lib/libXext.so /usr/lib/libXrender.so /usr/lib
/libX11.so /usr/lib/libxcb-xlib.so /usr/lib/libxcb.so /usr/lib/libXau.so
/usr/lib/libXdmcp.so -ldl -lvga -lpthread ../../src/shared/libicelibrary.a
keydown.o:/usr/lib/gcc/i486-slackware-linux/4.2.4/../../../../include/c++/4.2.4
/bits/stl_algobase.h:182: multiple definition of `FileLocations::Anibox_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:102: first defined here
keydown.o:/usr/lib/gcc/i486-slackware-linux/4.2.4/../../../../include/c++/4.2.4/bits/stl_algobase.h:182: multiple definition of `FileLocations::Gizmo_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:102: first defined here
keydown.o:/usr/lib/gcc/i486-slackware-linux/4.2.4/../../../../include/c++/4.2.4/bits/locale_facets.tcc:2562: multiple definition of `FileLocations::Image_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:102: first defined here
keydown.o:/usr/lib/gcc/i486-slackware-linux/4.2.4/../../../../include/c++/4.2.4/bits/locale_facets.tcc:2562: multiple definition of `FileLocations::Map_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:104: first defined here
keydown.o:/usr/lib/gcc/i486-slackware-linux/4.2.4/../../../../include/c++/4.2.4/bits/locale_facets.tcc:2562: multiple definition of `FileLocations::Song_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:104: first defined here
keydown.o:/usr/lib/gcc/i486-slackware-linux/4.2.4/../../../../include/c++/4.2.4/bits/stl_algobase.h:188: multiple definition of `FileLocations::Sound_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:106: first defined here
keygrabber.o:/usr/lib/gcc/i486-slackware-linux/4.2.4/../../../../include/c++/4.2.4/bits/stl_algobase.h:188: multiple definition of `FileLocations::Sound_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:106: first defined here
keygrabber.o:/home/icecube/project5/src/editor/keygrabber.cpp:71: multiple definition of `FileLocations::Song_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:104: first defined here
keygrabber.o:/home/icecube/project5/src/editor/keygrabber.cpp:71: multiple definition of `FileLocations::Map_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:104: first defined here
keygrabber.o:/home/icecube/project5/src/editor/keygrabber.cpp:71: multiple definition of `FileLocations::Image_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:102: first defined here
keygrabber.o:/home/icecube/project5/src/editor/keygrabber.cpp:69: multiple definition of `FileLocations::Gizmo_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:102: first defined here
keygrabber.o:/home/icecube/project5/src/editor/keygrabber.cpp:69: multiple definition of `FileLocations::Anibox_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:102: first defined here
mouseclick.o:/usr/lib/gcc/i486-slackware-linux/4.2.4/../../../../include/c++/4.2.4/bits/stl_algobase.h:182: multiple definition of `FileLocations::Anibox_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:102: first defined here
mouseclick.o:/usr/lib/gcc/i486-slackware-linux/4.2.4/../../../../include/c++/4.2.4/bits/stl_algobase.h:182: multiple definition of `FileLocations::Gizmo_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:102: first defined here
mouseclick.o:/usr/lib/gcc/i486-slackware-linux/4.2.4/../../../../include/c++/4.2.4/bits/locale_facets.tcc:2562: multiple definition of `FileLocations::Image_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:102: first defined here
mouseclick.o:/usr/lib/gcc/i486-slackware-linux/4.2.4/../../../../include/c++/4.2.4/bits/locale_facets.tcc:2562: multiple definition of `FileLocations::Map_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:104: first defined here
mouseclick.o:/usr/lib/gcc/i486-slackware-linux/4.2.4/../../../../include/c++/4.2.4/bits/locale_facets.tcc:2562: multiple definition of `FileLocations::Song_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:104: first defined here
mouseclick.o:/usr/lib/gcc/i486-slackware-linux/4.2.4/../../../../include/c++/4.2.4/bits/stl_algobase.h:188: multiple definition of `FileLocations::Sound_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:106: first defined here
movemouse.o:/usr/lib/gcc/i486-slackware-linux/4.2.4/../../../../include/c++/4.2.4/bits/stl_algobase.h:188: multiple definition of `FileLocations::Sound_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:106: first defined here
movemouse.o:/home/icecube/project5/src/editor/movemouse.cpp:66: multiple definition of `FileLocations::Song_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:104: first defined here
movemouse.o:/usr/lib/gcc/i486-slackware-linux/4.2.4/../../../../include/c++/4.2.4/bits/stl_algobase.h:187: multiple definition of `FileLocations::Map_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:104: first defined here
movemouse.o:/usr/lib/gcc/i486-slackware-linux/4.2.4/../../../../include/c++/4.2.4/bits/stl_algobase.h:187: multiple definition of `FileLocations::Image_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:102: first defined here
movemouse.o:/home/icecube/project5/src/editor/movemouse.cpp:65: multiple definition of `FileLocations::Gizmo_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:102: first defined here
movemouse.o:/home/icecube/project5/src/editor/movemouse.cpp:23: multiple definition of `FileLocations::Anibox_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:102: first defined here
navigate.o:/usr/lib/gcc/i486-slackware-linux/4.2.4/../../../../include/c++/4.2.4/bits/stl_algobase.h:188: multiple definition of `FileLocations::Sound_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:106: first defined here
navigate.o:/usr/lib/gcc/i486-slackware-linux/4.2.4/../../../../include/c++/4.2.4/bits/locale_facets.tcc:2562: multiple definition of `FileLocations::Song_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:104: first defined here
navigate.o:/usr/lib/gcc/i486-slackware-linux/4.2.4/../../../../include/c++/4.2.4/bits/locale_facets.tcc:2562: multiple definition of `FileLocations::Map_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:104: first defined here
navigate.o:/usr/lib/gcc/i486-slackware-linux/4.2.4/../../../../include/c++/4.2.4/bits/locale_facets.tcc:2562: multiple definition of `FileLocations::Image_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:102: first defined here
navigate.o:/usr/lib/gcc/i486-slackware-linux/4.2.4/../../../../include/c++/4.2.4/bits/stl_algobase.h:182: multiple definition of `FileLocations::Gizmo_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:102: first defined here
navigate.o:/usr/lib/gcc/i486-slackware-linux/4.2.4/../../../../include/c++/4.2.4/bits/stl_algobase.h:182: multiple definition of `FileLocations::Anibox_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:102: first defined here
paintblocks.o:/usr/lib/gcc/i486-slackware-linux/4.2.4/../../../../include/c++/4.2.4/bits/stl_algobase.h:188: multiple definition of `FileLocations::Sound_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:106: first defined here
paintblocks.o:/usr/lib/gcc/i486-slackware-linux/4.2.4/../../../../include/c++/4.2.4/bits/locale_facets.tcc:2562: multiple definition of `FileLocations::Song_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:104: first defined here
paintblocks.o:/usr/lib/gcc/i486-slackware-linux/4.2.4/../../../../include/c++/4.2.4/bits/locale_facets.tcc:2562: multiple definition of `FileLocations::Map_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:104: first defined here
paintblocks.o:/usr/lib/gcc/i486-slackware-linux/4.2.4/../../../../include/c++/4.2.4/bits/locale_facets.tcc:2562: multiple definition of `FileLocations::Image_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:102: first defined here
paintblocks.o:/usr/lib/gcc/i486-slackware-linux/4.2.4/../../../../include/c++/4.2.4/bits/stl_algobase.h:182: multiple definition of `FileLocations::Gizmo_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:102: first defined here
paintblocks.o:/usr/lib/gcc/i486-slackware-linux/4.2.4/../../../../include/c++/4.2.4/bits/stl_algobase.h:182: multiple definition of `FileLocations::Anibox_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:102: first defined here
paintfade.o:/usr/lib/gcc/i486-slackware-linux/4.2.4/../../../../include/c++/4.2.4/bits/stl_algobase.h:188: multiple definition of `FileLocations::Sound_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:106: first defined here
paintfade.o:/usr/lib/gcc/i486-slackware-linux/4.2.4/../../../../include/c++/4.2.4/bits/locale_facets.tcc:2562: multiple definition of `FileLocations::Song_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:104: first defined here
paintfade.o:/usr/lib/gcc/i486-slackware-linux/4.2.4/../../../../include/c++/4.2.4/bits/locale_facets.tcc:2562: multiple definition of `FileLocations::Map_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:104: first defined here
paintfade.o:/usr/lib/gcc/i486-slackware-linux/4.2.4/../../../../include/c++/4.2.4/bits/locale_facets.tcc:2562: multiple definition of `FileLocations::Image_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:102: first defined here
paintfade.o:/usr/lib/gcc/i486-slackware-linux/4.2.4/../../../../include/c++/4.2.4/bits/stl_algobase.h:182: multiple definition of `FileLocations::Gizmo_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:102: first defined here
paintfade.o:/usr/lib/gcc/i486-slackware-linux/4.2.4/../../../../include/c++/4.2.4/bits/stl_algobase.h:182: multiple definition of `FileLocations::Anibox_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:102: first defined here
paintgiz.o:/usr/lib/gcc/i486-slackware-linux/4.2.4/../../../../include/c++/4.2.4/bits/stl_algobase.h:188: multiple definition of `FileLocations::Sound_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:106: first defined here
paintgiz.o:/usr/lib/gcc/i486-slackware-linux/4.2.4/../../../../include/c++/4.2.4/bits/locale_facets.tcc:2562: multiple definition of `FileLocations::Song_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:104: first defined here
paintgiz.o:/usr/lib/gcc/i486-slackware-linux/4.2.4/../../../../include/c++/4.2.4/bits/locale_facets.tcc:2562: multiple definition of `FileLocations::Map_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:104: first defined here
paintgiz.o:/usr/lib/gcc/i486-slackware-linux/4.2.4/../../../../include/c++/4.2.4/bits/locale_facets.tcc:2562: multiple definition of `FileLocations::Image_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:102: first defined here
paintgiz.o:/usr/lib/gcc/i486-slackware-linux/4.2.4/../../../../include/c++/4.2.4/bits/stl_algobase.h:182: multiple definition of `FileLocations::Gizmo_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:102: first defined here
paintgiz.o:/usr/lib/gcc/i486-slackware-linux/4.2.4/../../../../include/c++/4.2.4/bits/stl_algobase.h:182: multiple definition of `FileLocations::Anibox_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:102: first defined here
painthero.o:/usr/lib/gcc/i486-slackware-linux/4.2.4/../../../../include/c++/4.2.4/bits/stl_algobase.h:188: multiple definition of `FileLocations::Sound_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:106: first defined here
painthero.o:/usr/lib/gcc/i486-slackware-linux/4.2.4/../../../../include/c++/4.2.4/bits/locale_facets.tcc:2562: multiple definition of `FileLocations::Song_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:104: first defined here
painthero.o:/usr/lib/gcc/i486-slackware-linux/4.2.4/../../../../include/c++/4.2.4/bits/locale_facets.tcc:2562: multiple definition of `FileLocations::Map_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:104: first defined here
painthero.o:/usr/lib/gcc/i486-slackware-linux/4.2.4/../../../../include/c++/4.2.4/bits/locale_facets.tcc:2562: multiple definition of `FileLocations::Image_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:102: first defined here
painthero.o:/usr/lib/gcc/i486-slackware-linux/4.2.4/../../../../include/c++/4.2.4/bits/stl_algobase.h:182: multiple definition of `FileLocations::Gizmo_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:102: first defined here
painthero.o:/usr/lib/gcc/i486-slackware-linux/4.2.4/../../../../include/c++/4.2.4/bits/stl_algobase.h:182: multiple definition of `FileLocations::Anibox_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:102: first defined here
paintmap.o:/usr/lib/gcc/i486-slackware-linux/4.2.4/../../../../include/c++/4.2.4/bits/stl_algobase.h:188: multiple definition of `FileLocations::Sound_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:106: first defined here
paintmap.o:/usr/lib/gcc/i486-slackware-linux/4.2.4/../../../../include/c++/4.2.4/bits/locale_facets.tcc:2562: multiple definition of `FileLocations::Song_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:104: first defined here
paintmap.o:/usr/lib/gcc/i486-slackware-linux/4.2.4/../../../../include/c++/4.2.4/bits/locale_facets.tcc:2562: multiple definition of `FileLocations::Map_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:104: first defined here
paintmap.o:/usr/lib/gcc/i486-slackware-linux/4.2.4/../../../../include/c++/4.2.4/bits/locale_facets.tcc:2562: multiple definition of `FileLocations::Image_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:102: first defined here
paintmap.o:/usr/lib/gcc/i486-slackware-linux/4.2.4/../../../../include/c++/4.2.4/bits/stl_algobase.h:182: multiple definition of `FileLocations::Gizmo_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:102: first defined here
paintmap.o:/usr/lib/gcc/i486-slackware-linux/4.2.4/../../../../include/c++/4.2.4/bits/stl_algobase.h:182: multiple definition of `FileLocations::Anibox_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:102: first defined here
paintmaster.o:/usr/lib/gcc/i486-slackware-linux/4.2.4/../../../../include/c++/4.2.4/bits/stl_algobase.h:182: multiple definition of `FileLocations::Anibox_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:102: first defined here
paintmaster.o:/usr/lib/gcc/i486-slackware-linux/4.2.4/../../../../include/c++/4.2.4/bits/stl_algobase.h:182: multiple definition of `FileLocations::Gizmo_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:102: first defined here
paintmaster.o:/usr/lib/gcc/i486-slackware-linux/4.2.4/../../../../include/c++/4.2.4/bits/locale_facets.tcc:2562: multiple definition of `FileLocations::Image_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:102: first defined here
paintmaster.o:/usr/lib/gcc/i486-slackware-linux/4.2.4/../../../../include/c++/4.2.4/bits/locale_facets.tcc:2562: multiple definition of `FileLocations::Map_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:104: first defined here
paintmaster.o:/usr/lib/gcc/i486-slackware-linux/4.2.4/../../../../include/c++/4.2.4/bits/locale_facets.tcc:2562: multiple definition of `FileLocations::Song_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:104: first defined here
paintmaster.o:/usr/lib/gcc/i486-slackware-linux/4.2.4/../../../../include/c++/4.2.4/bits/stl_algobase.h:188: multiple definition of `FileLocations::Sound_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:106: first defined here
paintmenu.o:/usr/lib/gcc/i486-slackware-linux/4.2.4/../../../../include/c++/4.2.4/bits/stl_algobase.h:188: multiple definition of `FileLocations::Sound_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:106: first defined here
paintmenu.o:/usr/lib/gcc/i486-slackware-linux/4.2.4/../../../../include/c++/4.2.4/bits/locale_facets.tcc:2562: multiple definition of `FileLocations::Song_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:104: first defined here
paintmenu.o:/usr/lib/gcc/i486-slackware-linux/4.2.4/../../../../include/c++/4.2.4/bits/locale_facets.tcc:2562: multiple definition of `FileLocations::Map_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:104: first defined here
paintmenu.o:/usr/lib/gcc/i486-slackware-linux/4.2.4/../../../../include/c++/4.2.4/bits/locale_facets.tcc:2562: multiple definition of `FileLocations::Image_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:102: first defined here
paintmenu.o:/usr/lib/gcc/i486-slackware-linux/4.2.4/../../../../include/c++/4.2.4/bits/stl_algobase.h:182: multiple definition of `FileLocations::Gizmo_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:102: first defined here
paintmenu.o:/usr/lib/gcc/i486-slackware-linux/4.2.4/../../../../include/c++/4.2.4/bits/stl_algobase.h:182: multiple definition of `FileLocations::Anibox_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:102: first defined here
pr5edit.o:/usr/lib/gcc/i486-slackware-linux/4.2.4/../../../../include/c++/4.2.4/bits/stl_algobase.h:188: multiple definition of `FileLocations::Sound_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:106: first defined here
pr5edit.o:/usr/lib/gcc/i486-slackware-linux/4.2.4/../../../../include/c++/4.2.4/bits/locale_facets.tcc:2562: multiple definition of `FileLocations::Song_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:104: first defined here
pr5edit.o:/usr/lib/gcc/i486-slackware-linux/4.2.4/../../../../include/c++/4.2.4/bits/locale_facets.tcc:2562: multiple definition of `FileLocations::Map_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:104: first defined here
pr5edit.o:/usr/lib/gcc/i486-slackware-linux/4.2.4/../../../../include/c++/4.2.4/bits/locale_facets.tcc:2562: multiple definition of `FileLocations::Image_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:102: first defined here
pr5edit.o:/usr/lib/gcc/i486-slackware-linux/4.2.4/../../../../include/c++/4.2.4/bits/stl_algobase.h:182: multiple definition of `FileLocations::Gizmo_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:102: first defined here
pr5edit.o:/usr/lib/gcc/i486-slackware-linux/4.2.4/../../../../include/c++/4.2.4/bits/stl_algobase.h:182: multiple definition of `FileLocations::Anibox_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:102: first defined here
superupdate.o:/usr/lib/gcc/i486-slackware-linux/4.2.4/../../../../include/c++/4.2.4/bits/stl_algobase.h:188: multiple definition of `FileLocations::Sound_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:106: first defined here
superupdate.o:/usr/lib/gcc/i486-slackware-linux/4.2.4/../../../../include/c++/4.2.4/bits/locale_facets.tcc:2562: multiple definition of `FileLocations::Song_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:104: first defined here
superupdate.o:/usr/lib/gcc/i486-slackware-linux/4.2.4/../../../../include/c++/4.2.4/bits/locale_facets.tcc:2562: multiple definition of `FileLocations::Map_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:104: first defined here
superupdate.o:/usr/lib/gcc/i486-slackware-linux/4.2.4/../../../../include/c++/4.2.4/bits/locale_facets.tcc:2562: multiple definition of `FileLocations::Image_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:102: first defined here
superupdate.o:/usr/lib/gcc/i486-slackware-linux/4.2.4/../../../../include/c++/4.2.4/bits/stl_algobase.h:182: multiple definition of `FileLocations::Gizmo_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:102: first defined here
superupdate.o:/usr/lib/gcc/i486-slackware-linux/4.2.4/../../../../include/c++/4.2.4/bits/stl_algobase.h:182: multiple definition of `FileLocations::Anibox_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:102: first defined here
../../src/shared/libicelibrary.a(Gizbox.o): In function `GizNode':
/home/icecube/project5/src/shared/Gizbox.cpp:23: multiple definition of `FileLocations::Anibox_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:102: first defined here
../../src/shared/libicelibrary.a(Gizbox.o): In function `GizNode':
/home/icecube/project5/src/shared/Gizbox.cpp:25: multiple definition of `FileLocations::Gizmo_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:102: first defined here
../../src/shared/libicelibrary.a(Gizbox.o): In function `GizNode':
/usr/lib/gcc/i486-slackware-linux/4.2.4/../../../../include/c++/4.2.4/bits/stl_algobase.h:187: multiple definition of `FileLocations::Image_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:102: first defined here
../../src/shared/libicelibrary.a(Gizbox.o): In function `GizNode':
/home/icecube/project5/src/shared/Gizbox.cpp:26: multiple definition of `FileLocations::Map_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:104: first defined here
../../src/shared/libicelibrary.a(Gizbox.o): In function `GizNode':
/home/icecube/project5/src/shared/Gizbox.cpp:26: multiple definition of `FileLocations::Song_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:104: first defined here
../../src/shared/libicelibrary.a(Gizbox.o): In function `GizNode':
/usr/lib/gcc/i486-slackware-linux/4.2.4/../../../../include/c++/4.2.4/bits/stl_algobase.h:188: multiple definition of `FileLocations::Sound_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:106: first defined here
../../src/shared/libicelibrary.a(Gizmo.o):/home/icecube/project5/src/shared/Gizmo.cpp:41: multiple definition of `FileLocations::Anibox_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:102: first defined here
../../src/shared/libicelibrary.a(Gizmo.o):/home/icecube/project5/src/shared/Gizmo.cpp:43: multiple definition of `FileLocations::Gizmo_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:102: first defined here
../../src/shared/libicelibrary.a(Gizmo.o):/usr/lib/gcc/i486-slackware-linux/4.2.4/../../../../include/c++/4.2.4/bits/basic_string.tcc:680: multiple
definition of `FileLocations::Image_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:102: first defined
here
../../src/shared/libicelibrary.a(Gizmo.o):/home/icecube/project5/src/shared
/Gizmo.cpp:65: multiple definition of `FileLocations::Map_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:104: first defined
here
../../src/shared/libicelibrary.a(Gizmo.o):/home/icecube/project5/src/shared
/Gizmo.cpp:84: multiple definition of `FileLocations::Song_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:104: first defined 
here
../../src/shared/libicelibrary.a(Gizmo.o):/usr/lib/gcc/i486-slackware-
linux/4.2.4/../../../../include/c++/4.2.4/bits/stl_algobase.h:188: multiple 
definition of `FileLocations::Sound_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:106: first defined 
here
../../src/shared/libicelibrary.a(Gizmoswitch.o):/usr/lib/gcc/i486-slackware-
linux/4.2.4/../../../../include/c++/4.2.4/bits/stl_algobase.h:188: multiple 
definition of `FileLocations::Sound_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:106: first defined 
here
../../src/shared/libicelibrary.a(Gizmoswitch.o):/usr/lib/gcc/i486-slackware-
linux/4.2.4/../../../../include/c++/4.2.4/bits/locale_facets.tcc:2562: multiple 
definition of `FileLocations::Song_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:104: first defined 
here
../../src/shared/libicelibrary.a(Gizmoswitch.o):/usr/lib/gcc/i486-slackware-
linux/4.2.4/../../../../include/c++/4.2.4/bits/locale_facets.tcc:2562: multiple 
definition of `FileLocations::Map_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:104: first defined 
here
../../src/shared/libicelibrary.a(Gizmoswitch.o):/usr/lib/gcc/i486-slackware-
linux/4.2.4/../../../../include/c++/4.2.4/bits/locale_facets.tcc:2562: multiple 
definition of `FileLocations::Image_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:102: first defined 
here
../../src/shared/libicelibrary.a(Gizmoswitch.o):/usr/lib/gcc/i486-slackware-
linux/4.2.4/../../../../include/c++/4.2.4/bits/stl_algobase.h:182: multiple 
definition of `FileLocations::Gizmo_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:102: first defined 
here
../../src/shared/libicelibrary.a(Gizmoswitch.o):/usr/lib/gcc/i486-slackware-
linux/4.2.4/../../../../include/c++/4.2.4/bits/stl_algobase.h:182: multiple 
definition of `FileLocations::Anibox_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:102: first defined 
here
../../src/shared/libicelibrary.a(MapBox.o):/usr/lib/gcc/i486-slackware-
linux/4.2.4/../../../../include/c++/4.2.4/bits/ios_base.h:123: multiple 
definition of `FileLocations::Anibox_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:102: first defined 
here
../../src/shared/libicelibrary.a(MapBox.o):/usr/lib/gcc/i486-slackware-
linux/4.2.4/../../../../include/c++/4.2.4/bits/ios_base.h:124: multiple 
definition of `FileLocations::Gizmo_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:102: first defined 
here
../../src/shared/libicelibrary.a(MapBox.o):/usr/lib/gcc/i486-slackware-
linux/4.2.4/../../../../include/c++/4.2.4/bits/locale_facets.tcc:2562: multiple 
definition of `FileLocations::Image_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:102: first defined 
here
../../src/shared/libicelibrary.a(MapBox.o):/usr/lib/gcc/i486-slackware-
linux/4.2.4/../../../../include/c++/4.2.4/bits/locale_facets.tcc:2562: multiple 
definition of `FileLocations::Map_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:104: first defined 
here
../../src/shared/libicelibrary.a(MapBox.o):/usr/lib/gcc/i486-slackware-
linux/4.2.4/../../../../include/c++/4.2.4/bits/ios_base.h:124: multiple 
definition of `FileLocations::Song_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:104: first defined 
here
../../src/shared/libicelibrary.a(MapBox.o):/usr/lib/gcc/i486-slackware-
linux/4.2.4/../../../../include/c++/4.2.4/bits/stl_algobase.h:188: multiple 
definition of `FileLocations::Sound_Path'
ice_edit.o:/home/icecube/project5/src/editor/ice_edit.cpp:106: first defined 
here
collect2: ld returned 1 exit status
gmake: *** [pr5edit] Error 1
*** Exited with status: 2 ***





I don't really understand it. I know if you declare a global variable in one .h file then you have to use the "extern" keyword in all the other .h files that depend on it. And I suppose FileLocations::Anibox_Path and all those are global variables so it's the same thing? But then why did the library compile just fine? I didn't put "extern" anything in Gizbox.h or MapBox.h and they both depend on Gizmo.h which depends on switchmaster.h. It's only when I try to compile the project that includes the library when I get all those multiple definition file errors. Why? I don't want any global variables anyway, should I even be using a namespace? Maybe I should change it to a struct and pass it everywhere? And how come things like std::string and std::cout and stuff don't give me linker errors? std is a namespace, right? Why don't #include <string> give me a crapload of multiple definition errors?
Advertisement
What you are doing is basically creating a copy of those globals in every .cpp file that includes your .h file. You need to prefix each variable declaration with extern, then pick one .cpp file that actually defines the variables (i.e. matches the extern-ified declarations but without the extern qualifier). That way you will get exactly one copy of the global variables, and each file using your header will be able to access them via the namespace.

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

uh... okay I put extern in front of each member variable in the namespace and now it all compiles. I guess it made them all "external" or something so now it doesn't try to make a new copy for every file that includes them? So now I have to define each one in some .cpp file's contructor I guess.

I guess it's impossible to make these member variables const then, huh? That's too bad, that's kind of what I wanted to do.

Hey I tried it the namespace way and it still doesn't work. I put extern in front of everything:
#ifndef SWITCHMASTER#define SWITCHMASTER//day is x cycles long  (x milliseconds on fast machine)#define DAYLEN 1800000//x cycles to shift daylight#define DAYSHIFT 2000.0f#define CLOUDSHIFT 2000.0f#define HORZ 1024#define VERT 768#define BPP 32//max length of a filename this program will work with (exluding extension, I think so really IFILE+4)#define IFILE 10//half the size of the hero you want to draw, make this obsolete eventually#define IHEROHALF 58#define DVAL 800//#define RATSLAM 3//#define RATDAMAGE 0.5f//the number of defined gizmo types -1//0 = standard player gizmo | NO AI     | 32 PNG's, 1 GIZ//1 = rat gizmo             | SIMPLE AI | 16 PNG's//2 = simple mill           | SPIN      | 3 PNG's//3 = stain                 |           | 4 PNG's#define IGIZ 3//number of defined anibox types -1#define IANI 0//the number of different possible layers -1#define ILAYER 4#define SCROLLSPEED 16.0f//should only be three sections this effects#define PROGRAMMER//#define VAULTCHECK//defined in MapBox.cpp constructor//(only declaring one of these, in MapBox.h)namespace Pathfinder{  extern std::string Anibox_Path;//="Data/Anibox/";  extern std::string Gizmo_Path;     //"Data/Gizmos/";  extern std::string Image_Path;     //="Data/Images/";  extern std::string Map_Path;       //="Data/Maps/";  extern std::string Song_Path;      //="Data/Songs/";  extern std::string Sound_Path;     //="Data/Sounds/";};#endif


And then in MapBox.cpp I did this:
MapBox::MapBox(){  Pathfinder::Anibox_Path="Data/Anibox/";  Pathfinder::Gizmo_Path="Data/Gizmos/";  Pathfinder::Image_Path="Data/Images/";  Pathfinder::Map_Path="Data/Maps/";  Pathfinder::Song_Path="Data/Songs/";  Pathfinder::Sound_Path="Data/Sounds/";}


The library with MapBox and everything compiled just fine again. But then when I tried to compile my editor which includes the library I got this:
cd '/home/icecube/project5/debug/./src/editor' && WANT_AUTOCONF_2_5="1"WANT_AUTOMAKE_1_6="1" LC_MESSAGES="C" LC_CTYPE="C" gmake pr5edit/bin/sh ../../libtool --tag=CXX --mode=link g++ -O0 -g3 -lGL -lSDL_mixer -lGLU -lSDL_image -o pr5edit ice_edit.o keydown.o keygrabber.o mouseclick.o movemouse.o navigate.o paintblocks.o paintfade.o paintgiz.o painthero.o paintmap.o paintmaster.o paintmenu.o pr5edit.o superupdate.o ../../src/shared/libicelibrary.a g++ -O0 -g3 -o pr5edit ice_edit.o keydown.o keygrabber.o mouseclick.o movemouse.o navigate.o paintblocks.o paintfade.o paintgiz.o painthero.o paintmap.o paintmaster.o paintmenu.o pr5edit.o superupdate.o /usr/lib/libGL.so -L/usr/X11R6/lib /usr/lib/libSDL_mixer.so -L/usr/lib -lGLU /usr/lib/libSDL_image.so -lpng /usr/lib/libtiff.so -ljpeg -lc -lz /usr/lib/libSDL.so -lm /usr/lib/libXrandr.so /usr/lib/libXext.so /usr/lib/libXrender.so /usr/lib/libX11.so /usr/lib/libxcb-xlib.so /usr/lib/libxcb.so /usr/lib/libXau.so /usr/lib/libXdmcp.so -ldl -lvga -lpthread ../../src/shared/libicelibrary.a../../src/shared/libicelibrary.a(MapBox.o): In function `MapBox':/home/icecube/project5/src/shared/MapBox.cpp:25: undefined reference to `Pathfinder::Anibox_Path'/home/icecube/project5/src/shared/MapBox.cpp:26: undefined reference to `Pathfinder::Gizmo_Path'/home/icecube/project5/src/shared/MapBox.cpp:27: undefined reference to `Pathfinder::Image_Path'/home/icecube/project5/src/shared/MapBox.cpp:28: undefined reference to `Pathfinder::Map_Path'/home/icecube/project5/src/shared/MapBox.cpp:29: undefined reference to `Pathfinder::Song_Path'/home/icecube/project5/src/shared/MapBox.cpp:30: undefined reference to `Pathfinder::Sound_Path'/home/icecube/project5/src/shared/MapBox.cpp:25: undefined reference to `Pathfinder::Anibox_Path'/home/icecube/project5/src/shared/MapBox.cpp:26: undefined reference to `Pathfinder::Gizmo_Path'/home/icecube/project5/src/shared/MapBox.cpp:27: undefined reference to `Pathfinder::Image_Path'/home/icecube/project5/src/shared/MapBox.cpp:28: undefined reference to `Pathfinder::Map_Path'/home/icecube/project5/src/shared/MapBox.cpp:29: undefined reference to `Pathfinder::Song_Path'/home/icecube/project5/src/shared/MapBox.cpp:30: undefined reference to `Pathfinder::Sound_Path'collect2: ld returned 1 exit statusgmake: *** [pr5edit] Error 1*** Exited with status: 2 ***
These are assignments, that is, just another function trying to use the globals.

//in headerextern std::string path;//in some source filestd::string path;
While generally dirty, sometimes generalities stay in the way of productivity. So generally try to avoid global variables and #define macros (e.g. will you always have a screen size of 1024x768x32). But that aside, I personally always have a file "globals.[cpp|cc|cxx|...]" that contains all definitions of your external variables, and which contains nothing and nothing but data. This avoids chaos in the future, when you want to change particular values.

So, go with something like (you don't have to #include the header with the external declarations):

globals.cpp
#include <string>namespace FileLocations {  std::string Anibox_Path = "Data/Anibox/";  std::string Gizmo_Path  = "Data/Gizmos/";  std::string Image_Path  = "Data/Images/";  std::string Map_Path    = "Data/Maps/";  std::string Song_Path   = "Data/Songs/";  std::string Sound_Path  = "Data/Sounds/";}


And if you don't intend to ever change the paths during runtime, make them const:

globals.cpp
#include <string>namespace FileLocations {  const std::string Anibox_Path = "Data/Anibox/";  const std::string Gizmo_Path  = "Data/Gizmos/";  const std::string Image_Path  = "Data/Images/";  const std::string Map_Path    = "Data/Maps/";  const std::string Song_Path   = "Data/Songs/";  const std::string Sound_Path  = "Data/Sounds/";}


file-locations.h
#include <string>namespace FileLocations {  extern const std::string Anibox_Path;  extern const std::string Gizmo_Path;  extern const std::string Image_Path;  extern const std::string Map_Path;  extern const std::string Song_Path;  extern const std::string Sound_Path;}


sidenote: Note that you also can underline your intent of variables being externally visible by writing like that:
namespace FileLocations {  extern const std::string Anibox_Path = "Data/Anibox/";  extern const std::string Gizmo_Path  = "Data/Gizmos/";[...]


Unfortunately, it doesn't prevent you from making errors like:
void f () {        extern const std::string s;        std::cout << s;}namespace { // <-- Anonymous namespace; the C++            // replacement of "static" at filescope.        extern const std::string s = "";}

This seems to be syntactically correct, as per gcc 3.x (sorry, no 4.x on this box), but will fail due to an undefined to s.
If the namespace way is "dirty" is there a better way to do it?
Quote:Original post by icecubeflower
If the namespace way is "dirty" is there a better way to do it?


Oh you misread my post, my fault. With "dirty", I meant that in objetc oriented languages you should generally avoid global variables; and in C++, you should try to avoid #define macros. Sometimes, they are the right thing (look at std::cout, which is a global variable), but in most cases not.

Using namespaces is actually a good technique to avoid name-pollution (look at PHP, which until 2008 lacked namespaces completely, and where you have thousands of functions with funky naming schemes like mysql_connect, just to avoid name-clashes).

Of course you could avoid using global variables by writing a class like that:

class Environment {public:    std::string getAniboxPath () const { return "Data/Anibox/"; }    [...]};int main () {    Environment env;    std::cout << env.getAniboxPath() << std::endl;}


If you use that, and somewhere in the future you decide to make those paths configurable (*), you are on the lucky side.


(*): Examplary code:

// Assuming "loadConfig()" to be a function to load values from some// ini-file.class Environment {public:    Environment () : aniboxPath (loadConfig("anibox-path")) {    }    std::string getAniboxPath () const { return aniboxPath; }private:    std::string aniboxPath;    [...]};int main () {    Environment env;    std::cout << env.getAniboxPath() << std::endl;}
Actually I was thinking it seemed dirty before you said so. I don't have any global variables but now I will with this namespace. And now I'll have to say extern everywhere, I don't like that. But I can only think of one other option. Define a class in a .h file and then declare an instance of it in a high level container, like MapBox, and pass it to all the lower containers.

...that's probably what I'll do. I mean I've gone this far without anything global, I don't really want to start now.
First of all, all of your #defines are practically global variables. People don't frown upon global variables because they're global, but because they make assumptions that tend to force certain (bad) designs. #define's do the same thing, and certain defines can even cause some very unexpected behavior. So as far as wanting to avoid global variables simply because they're global and "you don't have any yet" isn't a very good reason, especially since you pretty much do have them.

Secondly, and more importantly, globals seem to be a decent solution for you here. Passing an instance of a class along to every function in your project is sloppy and not much better than globals (it could even be worse).

So, how to make it work?
Change the bottom of switchmaster.h to this:
namespace FileLocations{  extern const std::string Anibox_Path;    //"Data/Anibox/";  extern const std::string Gizmo_Path;     //"Data/Gizmos/";  extern const std::string Image_Path;     //="Data/Images/";  extern const std::string Map_Path;       //="Data/Maps/";  extern const std::string Song_Path;      //="Data/Songs/";  extern const std::string Sound_Path;     //="Data/Sounds/";}


Make a file switchmaster.cpp with this content:
namespace FileLocations{  const std::string Anibox_Path("Data/Anibox/");  const std::string Gizmo_Path("Data/Gizmos/");  const std::string Image_Path("Data/Images/");  const std::string Map_Path("Data/Maps/");  const std::string Song_Path("Data/Songs/");  const std::string Sound_Path("Data/Sounds/");}


In any other code, do the following:
#include "switchmaster.h"void someFunction(){  // do some stuff  loadMap(FileLocations::Map_Path + "mapname.map");}


Notice that the extern keyword only appears in 1 place, the .h file declaration.
Notice that the variables can be const.
Notice that this is better than the "pass an instance of a class" method because a) someFunction() can run without depending on another function to inistialize that class for it, b) it's a lot clearer what's happening (i.e. you're grabbing the global Map_Path variable, not some Map_Path member of an object which could have multiple instances in the project - maybe that Map_Path is just for that object? who knows?

Hope this clears up what everyone else was trying to show you.

This topic is closed to new replies.

Advertisement