Precompiled Headers when building Static Library

K

Kevin Frey

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
requirement exists? I thought a precompiled header was simply a pre-parsed
representation of the header...)

My problem is that much of our project is compiled into static libraries
which are then linked by multiple targets within the project.

I find that I cannot link with the static library unless I also link with
the precompiled header object file that was involved in the compile of those
objects in the static library (we have a separate precompiled header per
target in case compile options differ between targets). Interestingly, I
tried putting the precompiled header object file into the library but the
linker will not resolve it from there.

Is this behaviour correct? It seems ludicrous that if I were selling a
static library how on earth would I ship it to customers? With the
precompiled object file separate? Or would I have to forego the benefits of
using precompiled headers?

I could of course be entirely wrong about all of this, so if that's the case
I would appreciate being informed as to what I am doing wrong and how to
correct it.

Kevin.
 
C

Carl Daniel [VC++ MVP]

Kevin Frey said:
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.

It's been available since 10/28 if you're an MSDN subscriber, and since 11/7
for everyone else.
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 requirement exists? I thought a precompiled header was simply a
pre-parsed representation of the header...)

I believe that it's so the linker can merge the symbol tables from the
PCH-builder into the PDB of the resulting image. Without it, all symbols
defined in the PCH would be missing from the PDB.
My problem is that much of our project is compiled into static libraries
which are then linked by multiple targets within the project.

I find that I cannot link with the static library unless I also link with
the precompiled header object file that was involved in the compile of
those objects in the static library (we have a separate precompiled header
per target in case compile options differ between targets). Interestingly,
I tried putting the precompiled header object file into the library but
the linker will not resolve it from there.

Is this behaviour correct? It seems ludicrous that if I were selling a
static library how on earth would I ship it to customers? With the
precompiled object file separate? Or would I have to forego the benefits
of using precompiled headers?

I could of course be entirely wrong about all of this, so if that's the
case I would appreciate being informed as to what I am doing wrong and how
to correct it.

I've never encountered the problem you describe - but it doesn't sound right
to me either. Hopefully someone else can shed some more light.

-cd
 
K

kevin_g_frey

I've never encountered the problem you describe - but it doesn't sound right
to me either. Hopefully someone else can shed some more light.

Are you saying you've built projects involving multiple static
libraries that were compiled with different precompiled headers and
you've never run into problems? Or are you saying you've simply never
heard of anyone else having this problem?
 
C

Carl Daniel [VC++ MVP]

Are you saying you've built projects involving multiple static
libraries that were compiled with different precompiled headers and
you've never run into problems? Or are you saying you've simply never
heard of anyone else having this problem?

Both.

-cd
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top