Re: precompiled headers question



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__proc___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_INCLUDE_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.
bruno_nos_pam_van_dooren@xxxxxxxxxxx
Remove only "_nos_pam"
.



Relevant Pages

  • Re: precompiled headers question
    ... All my source files are not in the same folder. ... which contains headers and sources of publishing functionality. ... Than at some point I changed project settings to not using pch, ... the compiler completely ignores everything ...
    (microsoft.public.dotnet.languages.vc)
  • Re: Using GDI+ in C++
    ... out how to modify library or API headers. ... that purpose, today, the compiler has a few options that ... The reason for it can be seen by looking at the output of: ... the definitions of the symbols mentioned in the complaints. ...
    (microsoft.public.vc.language)
  • Re: Is it possible to cancel a destruction ?
    ... Well compiling the VCL was quite simple but required a little bit of work. ... the VCL and then the compiler would simply use the VCL sources to build the ... The compiler was unable to find the resource files. ... delete such a folder without even thinking about it another further. ...
    (alt.comp.lang.borland-delphi)
  • Re: Mixed up e-mail bodies and headers
    ... There is no need to send a screenshot, as the e-mails in the folder ... It does look like Outlook keeps records of headers and ... bodies separate in its database and they are unsynchronized. ... Outlook doesn't keep the e-mail in its raw ...
    (microsoft.public.outlook)
  • Re: OE6 newsgroup reader problem...
    ... every time you open the newsgroup, ... Now return to "Get XXX headers at a time" and uncheck the option completely; ... unless you copied them to another folder for archiving. ... at a time", that is, to download all the headers again. ...
    (microsoft.public.windows.inetexplorer.ie6_outlookexpress)