1. fatal error C1010
此问题和预编译头文件有关。
每次编译项目时,编译器会把所有相关的文件复制进项目中并进行编译,但其实,这些被编译的文件中总有一些文件是不会变动的,比如标准库、STL和一些我们自己写的但基本不会更改的头文件等等,可是这些文件却要在每次编译时都被重新包含进项目中并重新编译。可不可以让它们只被编译一次?这样就可以大大缩短编译时间了。事实上确实可以,我们可以通过预编译头文件的方式做到这点。
但是使用预编译头文件可能报出: fatal error C1010
。
解决方案1: 不使用预编译头文件(注意设置时选择对应的平台)
解决方案2: 正确配置预编译头文件(注意设置时选择对应的平台)
- 创建两个文件:
pch.h
、pch.cpp
pch: pre-compiled header,文件名可以随意指定,只需后缀ok即可
- pch.h:
// pch.h: This is a precompiled header file. // pch.h: 这是一个预编译头文件 // Files listed below are compiled only once, improving build performance for future builds. // This also affects IntelliSense performance, including code completion and many code browsing features. // However, files listed here are ALL re-compiled if any one of them is updated between builds. // Do not add files here that you will be updating frequently as this negates the performance advantage. #ifndef PCH_H #define PCH_H // add headers that you want to pre-compile here // 将你需要进行预编译的头文件写在这里 #include "log.h" #include "cross_platform_socket.h" #endif //PCH_H
- pch.cpp
// pch.cpp: source file corresponding to the pre-compiled header #include "pch.h" // When you are using pre-compiled headers, this source file is necessary for compilation to succeed.
-
项目设置
-
右键项目,设置预编译头为
Create
见上图中的箭头上面一行的Precompiled Header
。
解决方案3: 单独对 pch.cpp 使用 create
- 此方案的前面两步和解决方案2一致,但是在预编译头的设置这里,只有pch.h的
Precompiled Header
设为 Create(右键该文件->属性),项目属性中Precompiled Header
设为Use
(右键项目->属性)。