473,804 Members | 2,126 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

precompiled headers question

Hi,

I am writing some unmanaged c++ code that would need to be compiled in the
future using compilers other than vc++. I'm using the feature of vc++ "use
precompiled headers", is there going to be any problem if I compile this
code on other compilers? I'm asking this because when I use pch *some* of my
cpp files has following as there first line

#include "StdAfx.h"

but if I dont use pch, I have to change that to

#include "../StdAfx.h"

Regards,

Ab.

Mar 31 '06 #1
8 1483
> I am writing some unmanaged c++ code that would need to be compiled in the
future using compilers other than vc++. I'm using the feature of vc++ "use
precompiled headers", is there going to be any problem if I compile this
code on other compilers? I'm asking this because when I use pch *some* of
my
cpp files has following as there first line

#include "StdAfx.h"

but if I dont use pch, I have to change that to

#include "../StdAfx.h"


Hi,

This will not be a problem. You can enable or disable the use of precompiled
headers in your project configuration properties. You don't have to change
anything to your sources at all.

Going to another compiler will not be a problem in that regard, but you have
to check whether you use microsoft specific features or not. you could /Za
to disable language extensions to insure that you only use ANSI.C++.

Btw GCC 4 also support precompiled headers I believe.

--

Kind regards,
Bruno van Dooren
br************* *********@hotma il.com
Remove only "_nos_pam"
Mar 31 '06 #2
headers in your project configuration properties. You don't have to change
anything to your sources at all.
then why do I have to change the "stdafx.h" to "../stdafx.h" when I'm not
using pch?

Should I delete this #include "stdafx.h" from the start of my *cpp* files
when NOT using pch?

Ab.
"Bruno van Dooren" <br************ **********@hotm ail.com> wrote in message
news:ex******** ******@TK2MSFTN GP10.phx.gbl...
I am writing some unmanaged c++ code that would need to be compiled in the future using compilers other than vc++. I'm using the feature of vc++ "use precompiled headers", is there going to be any problem if I compile this
code on other compilers? I'm asking this because when I use pch *some* of my
cpp files has following as there first line

#include "StdAfx.h"

but if I dont use pch, I have to change that to

#include "../StdAfx.h"


Hi,

This will not be a problem. You can enable or disable the use of

precompiled headers in your project configuration properties. You don't have to change
anything to your sources at all.

Going to another compiler will not be a problem in that regard, but you have to check whether you use microsoft specific features or not. you could /Za
to disable language extensions to insure that you only use ANSI.C++.

Btw GCC 4 also support precompiled headers I believe.

--

Kind regards,
Bruno van Dooren
br************* *********@hotma il.com
Remove only "_nos_pam"

Mar 31 '06 #3
>> headers in your project configuration properties. You don't have to
change
anything to your sources at all.
then why do I have to change the "stdafx.h" to "../stdafx.h" when I'm not
using pch?


You shouldn't have to. Just right click the file, select properties, go to
C++ ->precompiled headers.
there you can change the PCH usage.
You can also do this at project level.

Should I delete this #include "stdafx.h" from the start of my *cpp* files
when NOT using pch?


No, because most times it actually contains other headers.
Also, if the project is configured to use pch, you will get a compiler error
when you don't include it.
Using or not using PCH is a setting. It should not affect your sources at
all.

It is a technique for speeding up compilation times. nothing more.
--

Kind regards,
Bruno van Dooren
br************* *********@hotma il.com
Remove only "_nos_pam"
Mar 31 '06 #4
"Abubakar" <em**********@y ahoo.com> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
Hi,

I am writing some unmanaged c++ code that would need to be compiled in the
future using compilers other than vc++. I'm using the feature of vc++ "use
precompiled headers", is there going to be any problem if I compile this
code on other compilers? I'm asking this because when I use pch *some* of
my
cpp files has following as there first line

#include "StdAfx.h"

but if I dont use pch, I have to change that to

#include "../StdAfx.h"


Then you have path problems in your project environment.

When you're compiling with PCH, the compiler completely ignores everything
in the file up through #include "stdafx.h". The fact that you have to
change the path when you don't use PCH to me indicates that the compiler
can't find your stdafx.h in any of the standard places.

What does the directory structure of your project look like? In particular,
where are stdafx.h and the file containing the #include in relation to one
another?

-cd
Mar 31 '06 #5
> What does the directory structure of your project look like? In
particular,
where are stdafx.h and the file containing the #include in relation to one
All my source files are not in the same folder. I have made extra folders to
contain source and headers. For example, there is a folder called Publish,
which contains headers and sources of publishing functionality. When I added
these files to my project as new items, they had there first line as
"#include "stdafx.h"" . That was the time when my project settings had pch
enabled. Than at some point I changed project settings to not using pch,
after which when I compiled the project I started getting these errors that
there was no stdafx.h. But I knew that stdafx.h is at the root of the source
tree, so I just changed it to "#include "../stdafx.h"" and it compiled fine,
which also got me thinking why was it (lets say blockpublishing .cpp)
compiling before when it had no stdafx.h on its path. (my lack of cpp
knowledge).

I have other problems as well, related to header files includes. Like I have
a common.h file that has some utility functions and some global variables
that I intend to use at more than one place. Now I include common.h at one
file, lets say one.h and use its functions which works ok, and than at some
other place,lets say two.h, I include the common.h and compiler starts
giving me errors, while linking the source, saying that
"something__pro c___here" is already defined in "something.obj" . However if I
dont include common.h in two.h, the two.h has no idea of the things (global
functions and variables) that I write, which I assume will me visible to
two.h that are inside the common.h. Now the next thing I'm planning to do is
inlcude my common.h in stdafx.h and see what happens. Also will play with
#pragma once stuff which looks insteresting and I hope its not microsoft
specific.

The purpose I wrote this second para above is:
Having a C# background, I think I really need to read some really good and
detailed article on the problems that a dev can face while working on c++
projects having to do with #include. It would be great if you or anyone else
has some web links on this, or maybe discuss here.
Ab.
"Carl Daniel [VC++ MVP]" <cp************ *************** **@mvps.org.nos pam>
wrote in message news:uC******** ******@TK2MSFTN GP09.phx.gbl... "Abubakar" <em**********@y ahoo.com> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
Hi,

I am writing some unmanaged c++ code that would need to be compiled in the future using compilers other than vc++. I'm using the feature of vc++ "use precompiled headers", is there going to be any problem if I compile this
code on other compilers? I'm asking this because when I use pch *some* of my
cpp files has following as there first line

#include "StdAfx.h"

but if I dont use pch, I have to change that to

#include "../StdAfx.h"
Then you have path problems in your project environment.

When you're compiling with PCH, the compiler completely ignores everything
in the file up through #include "stdafx.h". The fact that you have to
change the path when you don't use PCH to me indicates that the compiler
can't find your stdafx.h in any of the standard places.

What does the directory structure of your project look like? In

particular, where are stdafx.h and the file containing the #include in relation to one
another?

-cd

Apr 3 '06 #6
> > What does the directory structure of your project look like? In
particular,
where are stdafx.h and the file containing the #include in relation to one
All my source files are not in the same folder. I have made extra folders to
contain source and headers. For example, there is a folder called Publish,
which contains headers and sources of publishing functionality. When I added
these files to my project as new items, they had there first line as
"#include "stdafx.h"" . That was the time when my project settings had pch
enabled. Than at some point I changed project settings to not using pch,
after which when I compiled the project I started getting these errors that
there was no stdafx.h. But I knew that stdafx.h is at the root of the source
tree, so I just changed it to "#include "../stdafx.h"" and it compiled fine,
which also got me thinking why was it (lets say blockpublishing .cpp)
compiling before when it had no stdafx.h on its path. (my lack of cpp
knowledge).


That is because the compiler will look for the PCH instead of trying to load
the real include file.

if you separate include and source files you have to add additional include
directories in your project settings. otherwise you have to explicitly tell
the compiler where those files are (by using ../..) and that removes
flexibility from your project layout.

I have other problems as well, related to header files includes. Like I have
a common.h file that has some utility functions and some global variables
that I intend to use at more than one place. Now I include common.h at one
file, lets say one.h and use its functions which works ok, and than at some
other place,lets say two.h, I include the common.h and compiler starts
giving me errors, while linking the source, saying that
"something__pro c___here" is already defined in "something.obj" . However if I
dont include common.h in two.h, the two.h has no idea of the things (global
functions and variables) that I write, which I assume will me visible to
two.h that are inside the common.h. Now the next thing I'm planning to do is
do it like this:
//common.h
extern int g_Global;
extern int MyFunction(void );

//common.cpp
#include "common.h"
int g_Global;
int MyFunction(void )
{
//...
}

that way there is only 1 definition, and you can use them by simply
including common.h
inlcude my common.h in stdafx.h and see what happens. Also will play with
#pragma once stuff which looks insteresting and I hope its not microsoft
specific.
another thing you'll see often is this:

#ifndef __SOME_INCLUDE_ GUARD__
#define__SOME_I NCLUDE_GUARD__

//declarations here

#endif

The purpose I wrote this second para above is:
Having a C# background, I think I really need to read some really good and
detailed article on the problems that a dev can face while working on c++
projects having to do with #include. It would be great if you or anyone else
has some web links on this, or maybe discuss here.


to find out if something is MSFT specific, find the topic in the MSDN help
collection. it is always mentioned if something is ANSI or microsoft specific.

www.codeproject.com is always a good place to start when looking for info.
if you are serious about C++ you should buy a good book. there are several.
my favorite is still 'the C++ programming language' by stroustrub
it can be a bit dull at times, but it is complete.

if you have specific questions you can always ask them here also.

--

Kind regards,
Bruno.
br************* *********@hotma il.com
Remove only "_nos_pam"
Apr 3 '06 #7

"Bruno van Dooren" <br************ **********@hotm ail.com> wrote in message
news:01******** *************** ***********@mic rosoft.com...
What does the directory structure of your project look like? In particular,
where are stdafx.h and the file containing the #include in relation to
one
All my source files are not in the same folder. I have made extra folders to contain source and headers. For example, there is a folder called Publish, which contains headers and sources of publishing functionality. When I added these files to my project as new items, they had there first line as
"#include "stdafx.h"" . That was the time when my project settings had pch enabled. Than at some point I changed project settings to not using pch,
after which when I compiled the project I started getting these errors that there was no stdafx.h. But I knew that stdafx.h is at the root of the source tree, so I just changed it to "#include "../stdafx.h"" and it compiled fine, which also got me thinking why was it (lets say blockpublishing .cpp)
compiling before when it had no stdafx.h on its path. (my lack of cpp
knowledge).


That is because the compiler will look for the PCH instead of trying to

load the real include file.

if you separate include and source files you have to add additional include directories in your project settings. otherwise you have to explicitly tell the compiler where those files are (by using ../..) and that removes
flexibility from your project layout.

I have other problems as well, related to header files includes. Like I have a common.h file that has some utility functions and some global variables that I intend to use at more than one place. Now I include common.h at one file, lets say one.h and use its functions which works ok, and than at some other place,lets say two.h, I include the common.h and compiler starts
giving me errors, while linking the source, saying that
"something__pro c___here" is already defined in "something.obj" . However if I dont include common.h in two.h, the two.h has no idea of the things (global functions and variables) that I write, which I assume will me visible to
two.h that are inside the common.h. Now the next thing I'm planning to do is

do it like this:
//common.h
extern int g_Global;
extern int MyFunction(void );

//common.cpp
#include "common.h"
int g_Global;
int MyFunction(void )
{
//...
}

that way there is only 1 definition, and you can use them by simply
including common.h
inlcude my common.h in stdafx.h and see what happens. Also will play
with #pragma once stuff which looks insteresting and I hope its not microsoft
specific.


another thing you'll see often is this:

#ifndef __SOME_INCLUDE_ GUARD__
#define__SOME_I NCLUDE_GUARD__

//declarations here

#endif

The purpose I wrote this second para above is:
Having a C# background, I think I really need to read some really good and detailed article on the problems that a dev can face while working on c++ projects having to do with #include. It would be great if you or anyone else has some web links on this, or maybe discuss here.


to find out if something is MSFT specific, find the topic in the MSDN help
collection. it is always mentioned if something is ANSI or microsoft

specific.
www.codeproject.com is always a good place to start when looking for info.
if you are serious about C++ you should buy a good book. there are several. my favorite is still 'the C++ programming language' by stroustrub
it can be a bit dull at times, but it is complete.

if you have specific questions you can always ask them here also.

--

Kind regards,
Bruno.
br************* *********@hotma il.com
Remove only "_nos_pam"

Apr 4 '06 #8
> do it like this:
//common.h
extern int g_Global;
extern int MyFunction(void );
This was very helpful.

Thanks for all other tips as well. My #include problems are settling slowly
n slowly :-)

Regards,

Abubakar.
"Bruno van Dooren" <br************ **********@hotm ail.com> wrote in message
news:01******** *************** ***********@mic rosoft.com...
What does the directory structure of your project look like? In

particular,
where are stdafx.h and the file containing the #include in relation to
one
All my source files are not in the same folder. I have made extra folders to contain source and headers. For example, there is a folder called Publish, which contains headers and sources of publishing functionality. When I added these files to my project as new items, they had there first line as
"#include "stdafx.h"" . That was the time when my project settings had pch enabled. Than at some point I changed project settings to not using pch,
after which when I compiled the project I started getting these errors that there was no stdafx.h. But I knew that stdafx.h is at the root of the source tree, so I just changed it to "#include "../stdafx.h"" and it compiled fine, which also got me thinking why was it (lets say blockpublishing .cpp)
compiling before when it had no stdafx.h on its path. (my lack of cpp
knowledge).


That is because the compiler will look for the PCH instead of trying to

load the real include file.

if you separate include and source files you have to add additional include directories in your project settings. otherwise you have to explicitly tell the compiler where those files are (by using ../..) and that removes
flexibility from your project layout.

I have other problems as well, related to header files includes. Like I have a common.h file that has some utility functions and some global variables that I intend to use at more than one place. Now I include common.h at one file, lets say one.h and use its functions which works ok, and than at some other place,lets say two.h, I include the common.h and compiler starts
giving me errors, while linking the source, saying that
"something__pro c___here" is already defined in "something.obj" . However if I dont include common.h in two.h, the two.h has no idea of the things (global functions and variables) that I write, which I assume will me visible to
two.h that are inside the common.h. Now the next thing I'm planning to do is

do it like this:
//common.h
extern int g_Global;
extern int MyFunction(void );

//common.cpp
#include "common.h"
int g_Global;
int MyFunction(void )
{
//...
}

that way there is only 1 definition, and you can use them by simply
including common.h
inlcude my common.h in stdafx.h and see what happens. Also will play
with #pragma once stuff which looks insteresting and I hope its not microsoft
specific.


another thing you'll see often is this:

#ifndef __SOME_INCLUDE_ GUARD__
#define__SOME_I NCLUDE_GUARD__

//declarations here

#endif

The purpose I wrote this second para above is:
Having a C# background, I think I really need to read some really good and detailed article on the problems that a dev can face while working on c++ projects having to do with #include. It would be great if you or anyone else has some web links on this, or maybe discuss here.


to find out if something is MSFT specific, find the topic in the MSDN help
collection. it is always mentioned if something is ANSI or microsoft

specific.
www.codeproject.com is always a good place to start when looking for info.
if you are serious about C++ you should buy a good book. there are several. my favorite is still 'the C++ programming language' by stroustrub
it can be a bit dull at times, but it is complete.

if you have specific questions you can always ask them here also.

--

Kind regards,
Bruno.
br************* *********@hotma il.com
Remove only "_nos_pam"

Apr 4 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
2191
by: Asfand Yar Qazi | last post by:
Hi, Now that GCC 3.4 has precompiled headers, I'm thinking I can stop using pimpls to speed up development time, as it may make life easier (declaring pimpls takes a long time...) What are the views of the experienced users of various C++ implementations? Do precompiled headers allow pimpls to be avoided while maintaining the same speed up of development time?
1
3661
by: JoeS | last post by:
Is there anyway to share a single pch file between projects in VC 7.0? I have 300+ projects each of which creates its own pch. All projects include the exact same header files in the precompiled header. Its takes about 7 seconds to create the precompiled header for each project. That's 35 minutes spent creating precompiled headers for all project! All of the projects use PDB files for debug info. I tried creating Precomp.pch in project...
4
2517
by: Andrew Ward | last post by:
Hi All, I was wondering if it is possible to use precompiled headers without having to include a <stdafx.h> or whatever in every source file. My problem is that I have a project that makes heavy usage of a large third party library which means after pre-processing each translation unit is around 1meg in size. There are reasons though why I cannot use the standard approach to precompiled headers. What I would like to do is somthing like...
0
1222
by: Bruno van Dooren | last post by:
Hi, I am working on a dll that exports COM interfaces, and i am having some troubles with the use of precompiled headers. the project compiles always, but if i use /Yu (default: use precompiled header) i get linker error: OPCServer.exp : warning LNK4070: /OUT:OPCServer.dll directive in .EXP differs from output filename '.\Debug/CIT_OPC_Server.dll'; ignoring directive
20
1635
by: Bonj | last post by:
Is it possible to avoid using precompiled headers on files that don't #include "stdafx.h". I have an ATL project,which has got a lot of ATL #includes in its stdafx.h. I now need to add some .c files to this project, that compile as hard raw C - not C++. The .c files obviously won't understand the <atlbase.h> etc that are in the stdafx.h. But if I leave the precompiled headers switch on, it complains that fatal end of file was found...
1
1211
by: dt | last post by:
Having troubles with my program and i believe it has something to do with my project settings for precompiled headers. This is what i have: my main cpp file, vector.h/cpp and polygon.h/cpp. vector.h includes math, polygon includes vector and gl/gl.h, and main includes windows.h, gl/gl.h, gl/glu.h, gl/glaux.h and polygon.h i've tried setting all of them to 'using precompiled headers' and i get: fatal error C1010: unexpected end of file...
0
1194
by: citizenkahn | last post by:
I read an article entitled "Sharing precompiled headers between projects" on this group. I am in the same situation as the requesting author, but the solution has not worked for me. Here is my situation, if anyone has a clue as to how I can solve this, please let me know. I am using VS.NET 2003 Arch. I have a solution two projects, a library and an exe. The exe depends upon the library. Both build with /zi in
1
1370
by: Alvo von Cossel I | last post by:
yo, i have a simple hello world win32 console application. it should work but there is an error. here is the most important part of the error: have you forgotten to add #include <stdfx.h> to your source code? stdfx.h is a precompiled header and i have deleted it but vc++ still asks me to include it. how do i change the precompiled header setting? --
3
1928
by: Kevin Frey | last post by:
I am working on a test migration of our project to Visual Studio 2005 Beta 2 as a precursor to the availability of the full release of VS2005. The most onerous problem so far concerns the requirement by LINK.EXE that if an object file has used precompiled headers, then the resulting "precompiled header object file" must also be one of the objects in the link. (Whilst it does not affect my problem - I would dearly like to know why this...
0
9711
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10343
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10335
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10088
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9169
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7633
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6862
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4306
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3831
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.