PRB: Fatal Error CK1017 Using Precompiled Headers
PSS ID Number: Q101481
Article last modified on 07-14-1994

1.00

WINDOWS


----------------------------------------------------------------------
The information in this article applies to:

 - Microsoft Visual C++ for Windows NT, version 1.0
----------------------------------------------------------------------

SYMPTOMS
========

An attempt to create a debug library that uses precompiled headers may fail
and generate the following messages:

   CVPACK : fatal error CK1017: cannot find precompiled types file;
            relink with file.obj
   LINK : warning LNK4027: CVPACK error

CAUSE
=====

When a source file is compiled with the /Yc and /Z7 options, the compiler
creates a precompiled header file that contains CodeView debugging
information. The error occurs when you store the precompiled header in a
library, use the library to build an object module, and the source code
does not refer to any of the functions that the precompiled header file
defines.

RESOLUTION
==========

There are two methods to work around this situation:

 - Specify the /Yl<symbol> compiler option switch, where <symbol>
   is replaced by a symbol of your choice. when you create
   precompiled header files that do not contain any function
   definitions. This switch directs the compiler to store the
   debugging information in the precompiled header file.

 - Specify the /Yd compiler option switch to add the CodeView from
   the precompiled header to each object module. This method is
   less desirable because it generally produces large object files
   which can increase the time required to link the application.

MORE INFORMATION
================

When you compile a module with the /Yc and /Yl<symbol> option
switches, the compiler creates the ___@@_PchDebugInfoLibrary_<symbol>
symbol and stores it in the object module. Any source files that you
compile with this precompiled header refer to the specified symbol.
This causes the linker to include the object module from the library.

The following code example demonstrates the problem.

Sample Code
-----------

/*
 * To demonstrate this problem, perform the following five steps:
 *
 * 1. Compile TEST1.C as follows: cl /Yctest.h /Z7 /c
 * 2. Compile TEST2.C as follows: cl /Yutest.h /Z7 /c
 * 3. Build a library that contains TEST1.OBJ and TEST2.OBJ as
 *    follows: lib /out:test.lib test1.obj test2.obj
 * 4. Compile TEST3.C as follows: cl /Yu test.h /Z7 /c
 * 5. Link the application as follows:
 *       link /debugtype:cv /debug:notmapped,full test3.obj test.lib
 *
 * To correct this problem, compile TEST1.C as follows:
 *    cl /Yctest.h /YlAnyName /Z7 /c
 * Then repeat steps 2 through 5 above.
 */

TEST.H
------

#include <stdio.h>

TEST1.C
-------

#include "test.h"

TEST2.C
-------

#include "test.h"

void test2func(void)
{
   printf("inside TEST2FUNC...\n");
}

TEST3.C
-------

#include "test.h"

void test2func(void);

void main(void)
{
   printf("inside MAIN...\n");
}

Additional reference words: 1.00 /YX hdrstop /Fp
KBCategory: Tls
KBSubCategory: CPPIss

=============================================================================

Copyright Microsoft Corporation 1994.
