Jump to content
357mag

How do I add a header file to my project?

Recommended Posts

I'm looking around the IDE for something that will allow me to add a header file to my project. Do I right-click on the project and just select Add Unit? I also need to add a .cpp file too.

Edited by 357mag

Share this post


Link to post

Oh I believe I found it. Anyway I made my first project that uses a header file to hold the function prototype, and a .cpp file that holds the implementation.

 

The int main( ) file I named Odd Or Even.cpp (The program determines whether two numbers are odd or even).

The header file I added to the program it holds the function prototype I named it MyLib.h

The additional .cpp file I added that holds the implementation I named it MyLib.cpp

 

I'm not too clear on the last file which C++ Builder generates when you create a new project. C++ Builder calls it PCH1.h. Here it is:

 

#ifdef _WIN32
#include <tchar.h>
#endif

bool isEven(int number);

But it seems like I have two function prototypes going on. One here in this PCH1.h file, and the other one in the MyLib.h file. I had to place the function prototype here because the compiler complained about an undeclared identifier without it. Then

I commented out the prototype in the MyLib.h file and rebuilt the project and it ran fine so I deleted that file.

 

But what is this PCH1.h file about with this code that automatically comes with it? PCH stands for what?

Edited by 357mag

Share this post


Link to post

PCH = pre compiled header. It's a file created at a full build by the compiler with the pure aim of speeding up compilation. In almost all cases you can just ignore it and let the compiler delete/recreate it as it needs to.

Share this post


Link to post

If you add a unit then the IDE adds both the *.cpp and .h files.

There can be cases where you have a .h file with no associated *.cpp file (and this is therefore not what the IDE calls a unit). 

In this case you can right click on the project name (= the exe file) in the project tree view and select add existing and navigate to the *.h file you want to add.

Share this post


Link to post

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

×