Board index » cppbuilder » Precompiled Header

Precompiled Header


2005-08-07 11:02:08 PM
cppbuilder12
I found that by including the following statement in my cpp files, the
compilation is reduced. Try it in your code.
#include <vcl.h>
#pragma hdrstop
<other headers>
 
 

Re:Precompiled Header

"tinyabs" < XXXX@XXXXX.COM >wrote in message
Quote
I found that by including the following statement in my cpp files, the
compilation is reduced. Try it in your code.

#include <vcl.h>
#pragma hdrstop
<other headers>
And if you optimize your headers, it'll be quicker still ;-)
Go to
s127096140.websitehome.co.uk/program/index.htm
where you can download Harold Howe's old BCBDev faq site. In there is an
article on how to do it.
Simon.
 

Re:Precompiled Header

"Simon D" <lightsOnNo1@home>wrote in message news:42f62d92$ XXXX@XXXXX.COM ...
Quote
"tinyabs" < XXXX@XXXXX.COM >wrote in message
news: XXXX@XXXXX.COM ...
>I found that by including the following statement in my cpp files, the
>compilation is reduced. Try it in your code.
>
>#include <vcl.h>
>#pragma hdrstop
><other headers>

And if you optimize your headers, it'll be quicker still ;-)
This is basically what we do for PCH. It reduces
build time significantly. It also doesn't force us
to include everything in non vcl classes, which most
of my group finds a bad thing.
 

{smallsort}

Re:Precompiled Header

This is what I do:
I make a list of all the header files that are included in the project
except for those which I will be changing. I then create a master header
file which includes all of them.
Assuming that I call it AllHead.h, each source file in my project is then
set to begin like this:
#include "allhead.h"
#pragma hdrstop
After that come any includes of header files that I will be changing and
which the particular source file uses.
I then go into Options|Project and set header files to be cached and set the
precompiled header file to be in the project directory. Assuming the
project name is MyProj then the header file name would be .\myproj.csm
To finish it I tell it to do a build and go have a cup of coffee. Once that
is done, the precompiled headers are created and making the project will be
quicker.
Allhead.h might look something like this:
-------------------
#ifndef ALLHEAD_H
#define ALLHEAD_H
#include <vcl.h>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#endif
-------------------
. Ed
Quote
tinyabs wrote in message
news: XXXX@XXXXX.COM ...

I found that by including the following statement in my cpp files, the
compilation is reduced. Try it in your code.

#include <vcl.h>
#pragma hdrstop
<other headers>
 

Re:Precompiled Header

"Duane Hebert" < XXXX@XXXXX.COM >wrote in message
[..]
By the way, does anyone have that Python script that generates "pch.h" out
of your project's source files? :)
 

Re:Precompiled Header

Danila Vershinin wrote:
Quote
By the way, does anyone have that Python script that generates "pch.h" out
of your project's source files? :)
Try this link:
web.archive.org/web/20041010002523/http://www.bcbdev.com/ftp/controls/pch.zip
PS: Use at your own risk.
H^2
 

Re:Precompiled Header

I forced that BCB 2006 generate and use precompiled header using a unique main header for all the application. But seemingly it dowsn't work properly, because BCB compiler is always counting a huge number codes for each unit. Why? I didn't have the same problem with BCB6.0. Is it a bug?
 

Re:Precompiled Header

"Hamid" < XXXX@XXXXX.COM >wrote in message
Quote

I forced that BCB 2006 generate and use precompiled header using a unique
main header for all the application. But seemingly it dowsn't work properly,
because BCB compiler is always counting a huge number codes for each unit.
Why? I didn't have the same problem with BCB6.0. Is it a bug?
Remember that if a header file contains initialized data, like math.h (or
DateUtils.h, which includes math.h), it cannot be pre-compiled. Therefore,
you have to be selective about which header files are included in the
pre-compiled header. Do you get any warnings about not being able to create
the pre-compiled header?
Are you using the #pragma hdrstop directive?
Did you give your pre-compiled header file a unique name?
- Dennis
 

Re:Precompiled Header

I don't have any of headers that prevents BCB compiler from making precompiled headers. In my main header I have included:
#include <vcl.h>
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
Moreover, BCB compiler doesn't give me any warning regarding this issue and still counts huge number of lines. Since my project includes many utints, it takes long that compiler compile it. I wonder why? you can test it yourself....
Thanx,
Hamid
 

Re:Precompiled Header

"Hamid" < XXXX@XXXXX.COM >wrote in message
Quote

I don't have any of headers that prevents BCB compiler from making
precompiled headers. In my main header I have included:

#include <vcl.h>
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
Okay, what do your source files look like that include the precompiled
header?
Quote
Moreover, BCB compiler doesn't give me any warning regarding this issue
and still counts huge number of lines. Since my project includes many
utints, it takes long that compiler compile it. I wonder why? you can test
it yourself....
I don't need to test it...I use pre-compiled headers too, and they work just
fine. Here's what I do:
First, I do not include vcl.h in my precompiled header file. Then in all of
my application source files, I include vcl.h and my precompiled header file
like this:
#include <vcl.h>
#include "MyPCH.h"
#pragma hdrstop
Another thing you should check is that you are including your pre-compiled
headers at the top of your source files *first* -- before any other header
files are included. In other words, do this:
#include "MyPCH.h"
#pragma hdrstop
#include "Unit1.h"
...*not* this:
#include "Unit1.h"
#include "MyPCH.h"
#pragma hdrstop
If you get this wrong, you will see the kind of behavior you are talking
about.
- Dennis
 

Re:Precompiled Header

I have a unit which plays the role of a main header for me. In its cpp file I have lines below:
#include "MainUnit.h"
#pragma hdrstop
//-------------------------------------------------------------#pragma package(smart_init)
//-------------------------------------------------------------
and in its header I write:
#ifndef MainUnitH
#define MainUnitH
//-------------------------------------------------------------#include <vcl.h>
#include "mainFormUnit.h"
#endif
//-------------------------------------------------------------
All of my units (mainFormUnit.h for instance) includes this main header as:
#include "ServerMainUnit.h"
#pragma hdrstop
//-------------------------------------------------------------#pragma package(smart_init)
#pragma resource "*.dfm"
TmainForm *mainForm;
//-------------------------------------------------------------__fastcall TmainForm::TmainForm(TComponent* Owner)
: TForm(Owner)
{
}
//-------------------------------------------------------------
Clearly the header of my mainForm includes some other header files such as:
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
Now my question is why the pre-compiled header is not made? When you make the similar simple project in BCB6.0, it works well. That is to say BCB compiler counts exactly the number of lines which I write in a cpp file (mainFormUnit.cpp for example) not the huge amount of lines each time.
 

Re:Precompiled Header

I meant MainUnit by ServerMainUnit. i.e they are as the same... It was my typing mistake in asking my question...
 

Re:Precompiled Header

"hamid" < XXXX@XXXXX.COM >wrote in message
Quote

I have a unit which plays the role of a main header for me. In its cpp
file I have lines below:
This is unnecessary. However, it isn't the cause of your problem.
Quote
All of my units (mainFormUnit.h for instance) includes this main header
as:


#include "ServerMainUnit.h"
#pragma hdrstop
//-------------------------------------------------------------#pragma
package(smart_init)
#pragma resource "*.dfm"
TmainForm *mainForm;
//-------------------------------------------------------------__fastcall
TmainForm::TmainForm(TComponent* Owner)
: TForm(Owner)
{
}
//-------------------------------------------------------------

Clearly the header of my mainForm includes some other header files such
as:

#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
Clearly? I don't see them anywhere! Where are they?
Quote
Now my question is why the pre-compiled header is not made? When you make
the similar simple project in BCB6.0, it works well. That is to say BCB
compiler counts exactly the number of lines which I write in a cpp file
(mainFormUnit.cpp for example) not the huge amount of lines each time.
As shown, your code should probably work. However, it is clear that you are
*not* showing your actual code. You say that the header of mainForm
includes other headers, but you don't show that header nor do you show where
that header is #include'd. Please show all relevant portions of your code;
otherwise it is very difficult for anyone to offer help.
- Dennis
 

Re:Precompiled Header

Thanx for your reply. That would be great if you let me know an email address to send a short sample.
 

Re:Precompiled Header

"hamid" < XXXX@XXXXX.COM >wrote in message
Quote

Thanx for your reply. That would be great if you let me know an email
address to send a short sample.
It would be much better to post the relevant portions of your code here so
that everyone has a chance to offer help and all readers can benefit from
the discussion.
- Dennis