Re: linking files
Posted: Tue Jun 01, 2010 11:06 am
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...
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...