Advertisement

#include problem

Started by December 20, 2000 09:40 AM
2 comments, last by benjamin bunny 24 years, 1 month ago
I've been writing a 3D engine with VC4.1 for a while now, and including all the files as follows: I have a main source file, 'mirage.cpp' which contains winmain() amongst other things. This is the only file which I have added to my project by using 'insert->file...' ('project->add to project->files...' in vc6.0). At the top of mirage.cpp file I have #include "include.h" and then lots of #include "[filename].cpp" in include.h is the includes for the header files required by each of the cpp files, as well as the standard headers required by the program. Because some cpp files require the header files of other cpp files I decided to include all the headers at the top of the program rather than opening them from within the individual cpp files. I've just woken up and my ability to make sense is somewhat diminished, so if you're lost at this stage , what I mean is, I have file1.cpp, file2.cpp and file1.h, file 2.h. Rather than having file1.h included at the top of file1.cpp and file2.h included at the top of file2.cpp, I'm including both header files at in include.h, which is included at the top of file1.cpp. File2.cpp is also included at the top of file1.cpp, just under the #include "include.h" Right, so anyway, that was all fine and dandy in vc4.1 because all the files were added to my fileView and classView and were compiled whenever I made changes to them. Since upgrading to VC6.0 I've found that the only file which is added to my classview and fileview is mirage.cpp. Aside from the problems with navigating the files, it is near-impossible to persuade the compiler to recompile them when I make changes to them as it assumes they are external and thus do not change. So I tried adding the cpp files to the project using 'project->add to project->files...' and found that when I built the project (unsurprisingly) they lacked the header files and caused lots of errors. Then I added an #include "includes.h" to each file and rebuilt the project, and this allowed the project to compile without error, but at the linker stage caused lots of these: file2.obj : error LNK2005: "int nipples" (?nipples@@3HA) already defined in file1.obj Although these errors can be fixed by using the /force linker option, I would really would like to know the proper way of doing this as I feel that would be cheating (besides which, it causes too many warnings). If anyone can help I'll buy you a beer next time you're round my way. (but you'll have to find me first ) http://www.geocities.com/ben32768 Edited by - benjamin bunny on 12/20/00 9:44:00 AM

____________________________________________________________www.elf-stone.com | Automated GL Extension Loading: GLee 5.00 for Win32 and Linux

Hi,

First, you shouldn''t #include .cpp files. The compiler will create .obj files from the .cpp files, and the linker combines them to make an .exe file.

You should add all of your .h and .cpp files to your project, and don''t worry about which VC will try and compile and link - It''s pretty smart.

So your .cpp files should have :
#include "includes.h"

And your include.h file should only have :
#include "file1.h"
#include "file2.h"

Hope this helps.

- Peter
Advertisement
when you declare a variable in a *.h file (header file)

use extern.

extern int variable;


* and in the *.cpp file declare it again
int variable = 0;

As always, the answer comes from myself. Thanks.

http://www.geocities.com/ben32768

____________________________________________________________www.elf-stone.com | Automated GL Extension Loading: GLee 5.00 for Win32 and Linux

This topic is closed to new replies.

Advertisement