![]() |
Dev-C++ - #include .cpp/.h files
Hi,
Can anyone explain the best way to include my own .cpp/.h file in Dev-C++ projects. I've been putting my files in the include directory, because if I actually add them to the project (Project-->Add to Project), they don't get included when I try to build the project. I just get 'whatever'-undeclared errors. If I try to #include the files whilst they are a part of the project I get multiple definition error. The only way I have figured out to include the files is to remove them from the project, then #include them from the include directory. Surely I'm missing something here? Another question I have whilst we are on the subject, is how do I include, say, string.h in multiple files in the same project. So I could use sting objects in more than just main (assuming #include <string> has also been used in main). Thanks, Cache. |
#include "MyFile.h"
will include a header file in the current project folder |
Thanks.
I've seen that in other peoples code before, I just thought it was a style thing. Any suggestion on how to include the same header file in multiple files from the same project? |
Well I don't know what I'm doing wrong but I'm still getting multiple definition error when I use #include "MathClass.cpp". Meaning when I use "" instead of <>
The error: multiple definition of `math::math()' I know there is no error in my actuall code, because it builds fine when the included file is not a part of the project and I just inlude it from the include folder. Any more help? EDIT: I just changed the file extention from .cpp to .h and it works fine now. |
There is some implication in your post that you have code in the header file(s). Bad idea. Compile source files separately and link them, or put all the code in one source file. When you see something like "filename" versus <filename>, don't presume stylistic reasons. That really easy to look up.
Including files is a way to reuse declarations in multiple source files. If there is code (definitions) in the headers, you will get multiple definitions when you reuse the file. The include directive, incidentally, is not very magical. Where ever you see one, just visualize that the contents of the included file are being cut and pasted into the source file at that point. The preprocessor is doing that before turning it over to the compiler. |
Perhaps it's best I just place everything in the same source file for now then. I'll look into this again when I have a better understanding of the whole process.
EDIT: and thanks for the suggestions. |
| All times are GMT -5. The time now is 8:46 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC