Sign in to follow this  
Rad94

Including Header Files in C++

Recommended Posts

Hi, I'm using Dev C++ for my programming projects right now. So far, I haven't been able to include header files in my program. For example: I make a cpp file called main_O I use #include "main_O.cpp" to try to include the file into my project. It doesn't work. #include "main_O.h" or #include "main_O.hpp" don't work either. Anybody know how I include header files into my projects? Any help is greatly appreciated!

Share this post


Link to post
Share on other sites
What, specifically, doesn't work?

My guess would be, you're getting an error that says something like,
Compiling...xxx.cpp(3): Could not include file "main_O.cpp": file does not exist or path is incorrect
If so, make sure your file is actually named "main_O.cpp". If your file doesn't have a cpp extension, it's just named "main_O", you just want to write #include "main_O".

Is that the problem?

Share this post


Link to post
Share on other sites
Quote:
Original post by Futurulus
What, specifically, doesn't work?

My guess would be, you're getting an error that says something like,
Compiling...xxx.cpp(3): Could not include file "main_O.cpp": file does not exist or path is incorrect
If so, make sure your file is actually named "main_O.cpp". If your file doesn't have a cpp extension, it's just named "main_O", you just want to write #include "main_O".

Is that the problem?


Nope it still doesn't work sorry.

Share this post


Link to post
Share on other sites
Quote:
Original post by 3Dgonewild
Have you added the header(and the source) in the project(Project->add to project) ?


Thats almost guaranteed to be your problem. Do as suggested, I'll bet you'll find that all works smoothly. Well, unless your code is...

I'm just teasing. ;)

FlyingIsFun1217

Share this post


Link to post
Share on other sites
Quote:
Original post by megamoscha
You include headerfiles(h, hpp, hxx or whatever you use for it) not source files (c, c++, cpp, cc, cxx, ...)


In dev c++ ,if you don't include the source files you're getting a bunch of errors.....

Share this post


Link to post
Share on other sites
Quote:
Original post by 3Dgonewild
Quote:
Original post by megamoscha
You include headerfiles(h, hpp, hxx or whatever you use for it) not source files (c, c++, cpp, cc, cxx, ...)


In dev c++ ,if you don't include the source files you're getting a bunch of errors.....


I used dev c++ myself and I never needed to include any cpp file. You add cpp files to your project, but you dont use #include with them.

Share this post


Link to post
Share on other sites
Quote:
Original post by 3Dgonewild
Quote:
Original post by megamoscha
You include headerfiles(h, hpp, hxx or whatever you use for it) not source files (c, c++, cpp, cc, cxx, ...)


In dev c++ ,if you don't include the source files you're getting a bunch of errors.....


Ah...I see. I made all my source files .cpp instead of .h. Now it works. Thanks!

Share this post


Link to post
Share on other sites
Quote:
Original post by megamoscha
Quote:
Original post by 3Dgonewild
Quote:
Original post by megamoscha
You include headerfiles(h, hpp, hxx or whatever you use for it) not source files (c, c++, cpp, cc, cxx, ...)


In dev c++ ,if you don't include the source files you're getting a bunch of errors.....


I used dev c++ myself and I never needed to include any cpp file. You add cpp files to your project, but you dont use #include with them.


What i posted:
Quote:

Have you added the header(and the source) in the project(Project->add to project) ?


&
Quote:

In dev c++ ,if you don't include the source files you're getting a bunch of errors.....


Did i say that you have to include the source(.cpp) in source files?..of course not!.

I said that in order to compile the project, you have to include the header and the source in the project. -.-!

Share this post


Link to post
Share on other sites
Quote:

Did i say that you have to include the source(.cpp) in source files?..of course not!.

I said that in order to compile the project, you have to include the header and the source in the project. -.-!


Ummm well, chances are you're doing something wrong try to describe the "bunch of errors" people might be able to help you out. You should probably use something else anyway like code::blocks or visual studio express [rolleyes]

Share this post


Link to post
Share on other sites
Dev-C++ is old and not updated anymore, so it's better to switch to other IDE. You can try Microsoft Visual Studio Express Edition, or Codeblocks. Both are free and both are pretty good.

Share this post


Link to post
Share on other sites
Quote:
Original post by Shuger
Dev-C++ is old and not updated anymore, so it's better to switch to other IDE. You can try Microsoft Visual Studio Express Edition, or Codeblocks. Both are free and both are pretty good.


Just because it's old and not really updated, does not mean that it's bad. It's still a GREAT IDE.

FlyingIsFun1217

Share this post


Link to post
Share on other sites
Quote:
Original post by FlyingIsFun1217
Just because it's old and not really updated, does not mean that it's bad. It's still a GREAT IDE.

A great IDE would have great debugger integration. Dev-CPP has crappy debugger integration. A great IDE would have great code completion. Dev-CPP: Crap again. Ditto for version control integration, refactoring... the list goes on and on. Dev-CPP was a good IDE for its day. Now there are better ones.

Share this post


Link to post
Share on other sites
Quote:
Original post by 3Dgonewild
Have you added the header(and the source) in the project(Project->add to project) ?


Actually, there's no need to include the header into any sane IDE (Dev-C++ included) if you're #including it properly. For example, any headers for a pre-compiled library you will #include but won't reference in the project. Since #include is a straight forward copy-and-paste of the file, it matters not whether that file is referenced by the project, since it's contents are being used anyways. That's not to say that you should never add header files to a project, it's just not necessary. It is *convenient* for editing, but will not cause compiler errors.

Of course, you're right that all source files that you want to compile must be added to the project.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this