Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual C++ Precompiled Headers errors

Update:

What are the effects of including stdafx.h in my header files?


I started on a C++ project in Linux/Eclipse CDT and imported it into Visual C++/Windows.

In Visual C++, I started using precompiled headers to speed up compilation and defined stdafx.cpp and stdafx.h.

Here's my stdafx.h

#pragma once

#include <string>
#include <vector>
#include <map>
...

and my stdafx.cpp

#include "stdafx.h"

In every .h and .cpp file, I have the following:

#pragma once //if in a header file
#include "stdafx.h"

For both release and debug, I have "Create Precompiled Header (/Yc)". It compiled fine in debug mode, but in release mode it keeps reporting

error LNK2005: ___@@_PchSym_@00@UfhvihUaszlaDUwlxfnvmghUnnlUhixUnnlPeDUnnlPeDUivovzhvUvmgrgbOlyq@ already defined in A.obj

If I switch both to "Use precompiled header", I get in both Debug and Release

fatal error C1854: cannot overwrite information formed during creation of the precompiled header in object file:

Does anyone know what's going on?

like image 993
jameszhao00 Avatar asked Sep 09 '09 01:09

jameszhao00


1 Answers

You put "create precompiled header" only for stdafx.cpp. Then "use precompiled header" for all of the other ".cpp" files. Finally, have include "stdafx.h" at the start of each ".cpp" file (not usually in the header files.

like image 124
1800 INFORMATION Avatar answered Oct 03 '22 00:10

1800 INFORMATION