The linking process isn't the same as the precompiling. the precompiler takes the included files and adds the code in them to the page. that is used to include header files in order for your program to identify and "know" your classes and other things you put in separate pages. thats why only the decorations are in the include files. the actual classes and function are written in the other cpp file, that after compilation linked all together. so the #include function adds code, the linker is a different thing, it links the .obj created after the compilation of each cpp file into one exe file. so what happed to you is simple, the precomiler added your cpp files to your main file, and all of the code was compiled to a obj file, but the other cpp files in your project was also compiled, so when the linker tried to link them all together, it found the exact same code in the main file, so there you have an error...
so you don't need to include cpp files, because they will be added to your program by your linker if they are in the same project. what you do need to include is the declaration of your classes, because otherwise your main function won't know it exists.
hope it helps
and by the way, if i'm wrong, correct me. and if you already got the answer, i'm sorry, i just didn't have the time to check all the comments...lol
Edit: i'v read your other problem.. I dunno what's the solution. maybe its something with codeblocks beacuse i never had that problem, when using - #ifndef in VS...
linking files
Moderator: Coders of Rage
-
- Chaos Rift Cool Newbie
- Posts: 85
- Joined: Wed Mar 17, 2010 4:32 pm
Re: linking files
I am getting an error "multiple definition of 'map' ", which is an array. The error seems to include everything that is declared in the same .h file, which mostly declares arrays, map would be declared as "bool map[15];".
- xiphirx
- Chaos Rift Junior
- Posts: 324
- Joined: Mon Mar 22, 2010 3:15 pm
- Current Project: ******** (Unkown for the time being)
- Favorite Gaming Platforms: PC
- Programming Language of Choice: C++
- Contact:
Re: linking files
ok, now look for map again in your code where you include that header, change or get rid of the variable.mary wrote:I am getting an error "multiple definition of 'map' ", which is an array. The error seems to include everything that is declared in the same .h file, which mostly declares arrays, map would be declared as "bool map[15];".
That or make sure you didnt declare it twice in your header
StarCraft II Zerg Strategy, open to all levels of players!
Looking for paid work :< Contact me if you are interested in creating a website, need a web design, or anything else you think I'm capable of
Looking for paid work :< Contact me if you are interested in creating a website, need a web design, or anything else you think I'm capable of
Re: linking files
if I take it away then an error appears in the .cpp that actually uses the array. I checked and its not declared twice in the header.
Re: linking files
I made all the variables extern (extern bool map[15]), and in a differnt folder I declared then did [bool map[15]], and the code seems to work, I have no clue why this would change things.