Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Precompiled headers

337 views
Skip to first unread message

Jakub Cermak

unread,
Jul 31, 2008, 6:36:24 AM7/31/08
to
Hello, I was using "No precompiled headers" in my project. Now I want to
start using them. I switched the compiler option to "Create precompiled
headers". It created new .pch file successfully.
But when I switch to "Use Precompiled headers" it gave me an error at all
source files at the "#include "stdafx.h"" line:
Error 7 fatal error C1093: API call 'ImportFile' failed '0x80070002' :
ErrorMessage: The system cannot find the file specified. c:\Documents and
Settings\Administrator\My Documents\Visual Studio
2005\Projects\czelta35\MCpp\MessageDispatcher.cpp 1
The pch file is there, the stdafx.h file is in include path, so I dont know
what can be wrong. Any ideas?
It's Visual Studio 2005 SP1, C++/CLI project

Thanks

--
Jakub Cermak

Ron AF Greve

unread,
Jul 31, 2008, 7:49:04 AM7/31/08
to
Hi,

You probably did, but did you try a rebuild (in case this is a stale pch
file hanging around).

Regards, Ron AF Greve

http://www.InformationSuperHighway.eu

"Jakub Cermak" <Jakub...@discussions.microsoft.com> wrote in message
news:6D92F620-E3F4-4ED6...@microsoft.com...

Jakub Cermak

unread,
Jul 31, 2008, 8:11:00 AM7/31/08
to
Hello, of course I tried to clean & rebuild everything (that's one of my
first reactions to linker errors) but it didn't help.
--
Jakub Cermak

Carl Daniel [VC++ MVP]

unread,
Jul 31, 2008, 10:10:56 AM7/31/08
to

To use precompiled headers you should have:

* A single file, typically named stdax.cpp that's compiled with /Yc (Create
PCH File). That .cpp file typically #includes only a single header file,
traditionally named stdafx.h.

* A single header file which defines or includes all of the common
definitions for your project. In practice, it's rarely worth putting
anything other than Windows or framework (MFC, ATL) headers and global
#defines in your precompiled header file. You should NOT put code in your
stdafx.h file (e.g. class or variable definitions)

* All other files must #include "stdafx.h" as (important here) The Very Fist
Non Comment Line In The File. All other files must be compiled with /Yu (use
PCH file).

Verify that you've satisfied the above requirements.

What exactly is in your stdafx.h file? Where is the file located relative
to the rest of the project?

-cd


Jakub Cermak

unread,
Jul 31, 2008, 11:35:27 AM7/31/08
to
Hello,
(1) I have the file, I set it to /Yc while the project settings was /Yu, but
it didn't helped. My StdAfx.cpp:

#include "stdafx.h"

(2) I do have this one. Content of StdAfx.h:
#pragma once

#using <mscorlib.dll>
#include <iostream>

#define LEAN_AND_MEAN
#include <windows.h>

#include <vector>
#include <ctime>
#include <cstdlib>
#include <cmath>
#include <memory>
#include <vector>
#include <map>
#include <string>
#include <vcclr.h>
#include <deque>
#include <sstream>
#include <stdio.h>

(3) I checked all .cpp files and all of them has the #include "stdafx.h" as
the first line.

And both stdafx.h and .cpp are located in the $(SolutionDir)/DaqCpp
My project root is $(SolutionDir)/Daq

Anything suspicious or causing problems?

--
Jakub Cermak

David Wilkinson

unread,
Jul 31, 2008, 11:41:49 AM7/31/08
to

Maybe

#using <mscorlib.dll>

should come after

#include <windows.h>

--
David Wilkinson
Visual C++ MVP

Carl Daniel [VC++ MVP]

unread,
Jul 31, 2008, 3:32:57 PM7/31/08
to
David Wilkinson wrote:

> Jakub Cermak wrote:
>> Anything suspicious or causing problems?
>
> Maybe
>
> #using <mscorlib.dll>

I too would be suspicious of the #using. Since the error message refers to
a .NET/CLR function being called, I'd try moving the #using out of the PCH
file and see if that fixes it.

-cd


David Wilkinson

unread,
Jul 31, 2008, 4:10:17 PM7/31/08
to
Carl Daniel [VC++ MVP] wrote:

Carl:

Actually, what does this using directive do if the project is already compiled
with /clr ?

So many things puzzle me about how C++/CLI works ...

Carl Daniel [VC++ MVP]

unread,
Aug 1, 2008, 12:34:10 AM8/1/08
to

#using does something sort of equivalent to building a header file from the
assembly's meta data and then feeding that header to the compiler. Of
course, no header is actually generated - but that's the effect.

It's equivalent to the C# compiler's /reference command-line option or the
C++ compiler's /FU command line option.

-cd


Jakub Cermak

unread,
Aug 1, 2008, 4:49:01 AM8/1/08
to
I removed the #using and #include <vcclr.h> (it's something about CLR too)
and I put them directly to files where they are needed and - IT COMPILES!
Thank you :)
--
Jakub Cermak

"Carl Daniel [VC++ MVP]" wrote:

David Wilkinson

unread,
Aug 1, 2008, 8:05:26 AM8/1/08
to

Thanks, Carl, but ...

I don't know much about C++/CLI, but I did work through the C++/CLI examples in
Ivor Horton's book (2005 version, but using VS2008).

In these sample solutions I do not see any #using directives in the source, but
do I see a bunch of /FU's on the command line, such as

/FU "c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.dll"

However I do not see one for mscorlib.dll. Why is that?

Carl Daniel [VC++ MVP]

unread,
Aug 1, 2008, 10:20:52 AM8/1/08
to

It's built in to the compiler to always force a reference to mscorlib. Use
of #using is strictly optional - it's not unlike using #pragma
comment(lib...) to pull a library into the link without having it listed
explicitly in the linker inputs.

-cd


David Wilkinson

unread,
Aug 1, 2008, 10:48:35 AM8/1/08
to


Thanks, Carl.

One little mystery cleared up. But many more remain ...

0 new messages