C++ Precompiled Headers in VS2002 Topic is solved

Do you have a question about makefiles, a compiler or IDE you are using and need to know how to set it up for wxWidgets or why it doesn't compile but other IDE's do ? Post your questions here.
Post Reply
User avatar
Disch
Experienced Solver
Experienced Solver
Posts: 99
Joined: Wed Oct 17, 2007 2:01 am

C++ Precompiled Headers in VS2002

Post by Disch » Mon Jan 26, 2009 9:16 pm

Hey. I'm completely new to the whole precompiled header thing. Up until now I haven't been using them, and have just been enduring the compile times. Now I'm interested in trying out precompiled headers to see if they can cut down on compile time.

I checked the wiki and available documentation, and unless I'm misunderstanding... the only thing I have to do is this:

Code: Select all

#include "wx/wxprec.h"

#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif
Is that it? I'm doing that and not noticing a .pch file anywhere in my project. Compile time doesn't seem any shorter, either (I'm doing this in a virtually empty project for testing). Is there some compiler settings I need to set up? Do I need to compile wx with some options?

Any help appreciated.

rodrigod
I live to help wx-kind
I live to help wx-kind
Posts: 172
Joined: Thu Jun 26, 2008 8:50 pm

Post by rodrigod » Wed Feb 04, 2009 4:36 pm

AFAIK the compile time will only make a difference if you have a project with many files that use the precompiled header.

I use that precompiled header also and you can find it in your intermediate files folder. It is by default in the DEBUG or RELEASE folder under the project folder.

User avatar
Disch
Experienced Solver
Experienced Solver
Posts: 99
Joined: Wed Oct 17, 2007 2:01 am

Post by Disch » Thu Feb 05, 2009 6:51 pm

rodrigod wrote:I use that precompiled header also and you can find it in your intermediate files folder. It is by default in the DEBUG or RELEASE folder under the project folder.
I just checked again to be sure and there are no pch files in any of my project's folders. Do you mean *my* project folder? Or the wx project folder?

A full scan of my HD relvealed several .pch files in \build\msw\vc_msw*\. Could these be the pch files used? I find that somewhat unlikely.

rodrigod
I live to help wx-kind
I live to help wx-kind
Posts: 172
Joined: Thu Jun 26, 2008 8:50 pm

Post by rodrigod » Fri Feb 06, 2009 1:26 pm

How did you create the precompiled header? Did you just use automatic? Have you already compiled your project?

It's better to set your .cpp files to use the precompiled header you want "example.h" and set "example.cpp" to create. you do this on the project settings.

And by your project folder I meant your current project folder not wx project folder.

User avatar
Disch
Experienced Solver
Experienced Solver
Posts: 99
Joined: Wed Oct 17, 2007 2:01 am

Post by Disch » Fri Feb 06, 2009 3:48 pm

rodrigod wrote:How did you create the precompiled header? Did you just use automatic? Have you already compiled your project?
Well I guess this is my question. I didn't create the precompiled header. I'm totally new to this PCH stuff and I haven't been able to find any useful info on it in the wiki here or anything. I posted everything I know about the process to get a precompiled header working in my first post in this thread.
It's better to set your .cpp files to use the precompiled header you want "example.h" and set "example.cpp" to create. you do this on the project settings.
Okay -- this is what I was missing. I see this option in the project settings now. Tinkered with it a bit to generate then use the pch file -- and now I got it working. Compile time cut down dramatically! Excellent.

Although I'm not sure I understand the need for "example.cpp" here. It looks like I create the pch file from just a single .h file. I don't see the need to tie that .h file to a .cpp file. Is there a reason I should do this? Seems unnecessary to me.

Also it appears as though I have to include the header file in every source file in my project if I do this. Even in files which don't use wx. Failure to include results in an "unexpected end of file while looking for pch directive" error. Is there any way to avoid this? If someone tries to compile this without pch I'd hate for wx to be included in tons of files it doesn't need to be in.

rodrigod
I live to help wx-kind
I live to help wx-kind
Posts: 172
Joined: Thu Jun 26, 2008 8:50 pm

Post by rodrigod » Sun Feb 08, 2009 5:25 pm

example.cpp would be just like this

Code: Select all

#include "example.h"
It is set to create the pch. At least it is how I do it, copied it from microsoft when it creates a project with mfc automatically.

If you dont want a file to use the pch you go to it's setting and set it not to use precompiled header

User avatar
Disch
Experienced Solver
Experienced Solver
Posts: 99
Joined: Wed Oct 17, 2007 2:01 am

Post by Disch » Sun Feb 08, 2009 9:41 pm

Yeah I don't see the point to having that example.cpp. Seems like an extra needless file -- the PCH is created and included fine without it... all you need is to have any file in the project include the header (at least from what I've been able to tell).

Blech @ per-file settings, but I guess that'll do. I wonder how much all of this complicates things if you try to migrate to another compiler like g++.

Thanks a million, rodrigod! I appreciate the help!

Post Reply