Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Nov 24th, 2005, 9:07 PM   #1
Cache
Hobbyist
 
Join Date: Sep 2005
Posts: 261
Rep Power: 4 Cache is on a distinguished road
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.
Cache is offline   Reply With Quote
Old Nov 24th, 2005, 9:12 PM   #2
B3TA_SCR1PT3R
Hobbyist Programmer
 
B3TA_SCR1PT3R's Avatar
 
Join Date: Jul 2005
Location: Dallas, Texas
Posts: 101
Rep Power: 0 B3TA_SCR1PT3R is an unknown quantity at this point
Send a message via AIM to B3TA_SCR1PT3R
#include "MyFile.h"

will include a header file in the current project folder
__________________
Hoes telling me to calm down but I'm like fuck that shit!
B3TA_SCR1PT3R is offline   Reply With Quote
Old Nov 25th, 2005, 3:13 AM   #3
Cache
Hobbyist
 
Join Date: Sep 2005
Posts: 261
Rep Power: 4 Cache is on a distinguished road
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?
Cache is offline   Reply With Quote
Old Nov 25th, 2005, 5:22 AM   #4
Cache
Hobbyist
 
Join Date: Sep 2005
Posts: 261
Rep Power: 4 Cache is on a distinguished road
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.
Cache is offline   Reply With Quote
Old Nov 25th, 2005, 7:11 AM   #5
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
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.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Nov 25th, 2005, 11:34 AM   #6
Cache
Hobbyist
 
Join Date: Sep 2005
Posts: 261
Rep Power: 4 Cache is on a distinguished road
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.
Cache is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 4:47 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC