Page 2 of 2

Re: linking files

Posted: Tue Jun 01, 2010 11:06 am
by Avishaiozeri
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...

Re: linking files

Posted: Wed Jun 02, 2010 1:07 pm
by mary
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];".

Re: linking files

Posted: Wed Jun 02, 2010 1:14 pm
by xiphirx
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];".
ok, now look for map again in your code where you include that header, change or get rid of the variable.

That or make sure you didnt declare it twice in your header

Re: linking files

Posted: Wed Jun 02, 2010 1:17 pm
by mary
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

Posted: Wed Jun 02, 2010 1:31 pm
by mary
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.