Board index » cppbuilder » Adding a .cpp does not add its .h

Adding a .cpp does not add its .h

When I add an existing .cpp file to a project it does not add the
related .h
But if I select File/New and Add a unit both the new .cpp and .h are
added to the project.
I know this because files that are not in the project have the full path
displayed in the edit window and you cannot compile it.

How do I add a existing .cpp and have it .h added too?

thanx
-ray

 

Re:Adding a .cpp does not add its .h


Quote
> How do I add a existing .cpp and have it .h added too?

.h files are never part of your project and are not added, as you claimed,
by File | New -> Unit. What exactly do you want to happen?

--
Anduin Withers

Re:Adding a .cpp does not add its .h


If the .h is not 'added', then if I have it open and make changes to it I must
click on the .cpp to compile the unit, whereas if its added then I can click
compile the unit with either the .cpp or .h open.

When the fullpath is specified in the caption of the edit window then borland
thinks the file is not 'in' the project and you cannot compile it(.cpp or .h),
if the file name is just in the caption the you can compile it.

Its just a matter of convienince and BCB4 did it, but BCB5 does not.

Quote
> > How do I add a existing .cpp and have it .h added too?

> .h files are never part of your project and are not added, as you claimed,
> by File | New -> Unit. What exactly do you want to happen?

> --
> Anduin Withers

Re:Adding a .cpp does not add its .h


Quote
"Ramon Donnell" <r...@nronline.com> wrote in message

news:3AF21B99.B836D69B@nronline.com...

Quote
> If the .h is not 'added', then if I have it open and make changes to it I
must
> click on the .cpp to compile the unit, whereas if its added then I can
click
> compile the unit with either the .cpp or .h open.

This is due to a 'feature' of BCB called header guards.  In all VCL headers
you will see a header guard as such

#ifndef MyUnitH
#define MyUnitH

#endif

If you add MyUnit.cpp to the project and there is a header MyUnit.h with the
above header guard, BCB will treat them as a unit so 'Alt+F9' will work from
either the header or the cpp.  If you used a different style header guard,
e.g.

#ifndef _my_unit_h
#define _my_unit_h

#endif

BCB wouldn't treat them as a unit, and so 'Alt+F9' wouldn't work.  To fix
it, add the cpp to the project as normal, change the header guard to be of
the above format, close both the header, and cpp from the IDE, re-open the
cpp and then 'Ctrl+F6' to open the header, and voila! You can now compile
unit from either file.

Strange but true (and very annoying).  Why it can't just see a Header with
the same name as the cpp in the same directory, and treat them as one when
you compile I don't know.  I hang up from Delphi, I guess.

Have a look at the help (in BCB 5)

Whats New | Project and Project Manager enhancements | Handling the .CPP and
.H file as a set

Cheers

Russell

Other Threads