VS2019 常见错误

1. fatal error C1010

此问题和预编译头文件有关。
每次编译项目时,编译器会把所有相关的文件复制进项目中并进行编译,但其实,这些被编译的文件中总有一些文件是不会变动的,比如标准库、STL和一些我们自己写的但基本不会更改的头文件等等,可是这些文件却要在每次编译时都被重新包含进项目中并重新编译。可不可以让它们只被编译一次?这样就可以大大缩短编译时间了。事实上确实可以,我们可以通过预编译头文件的方式做到这点。
但是使用预编译头文件可能报出: fatal error C1010
解决方案1: 不使用预编译头文件(注意设置时选择对应的平台)
不使用预编译头文件
解决方案2: 正确配置预编译头文件(注意设置时选择对应的平台)

  1. 创建两个文件: pch.hpch.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.
    
  1. 项目设置
    在这里插入图片描述

  2. 右键项目,设置预编译头为 Create
    见上图中的箭头上面一行的 Precompiled Header

解决方案3: 单独对 pch.cpp 使用 create

  • 此方案的前面两步和解决方案2一致,但是在预编译头的设置这里,只有pch.h的 Precompiled Header 设为 Create(右键该文件->属性),项目属性中 Precompiled Header 设为 Use(右键项目->属性)。
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值