-2

虽然我的静态库工作正常,但我注意到默认设置带有以下文件:

  • 标准数据文件
  • stdafx.cpp
  • targetver.h

我不希望这个库很大。我希望尽可能地最小化。是否需要 stdafx.h/.cpp?

它们如何出现在我的项目中:

标准数据文件

// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//

#pragma once

#include "targetver.h"

#define WIN32_LEAN_AND_MEAN             // Exclude rarely-used stuff from Windows headers



// TODO: reference additional headers your program requires here
#include "mathlib.h"   // My main library

stdafx.cpp

// stdafx.cpp : source file that includes just the standard includes
// MathLib.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information

#include "stdafx.h"

// TODO: reference any additional headers you need in STDAFX.H
// and not in this file

targetver.h

#pragma once

// Including SDKDDKVer.h defines the highest available Windows platform.

// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and
// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h.

#include <SDKDDKVer.h>
4

2 回答 2

2

如果你不使用预编译的头文件,你可以删除文件,从代码中删除相关的包含。只有在实际使用该功能时才需要预编译的头文件。

同样在项目属性 -> C/C++ -> Precompiled headers 下,在 Precompiled Header 字段中选择Not Using Precompiled Headers 。

于 2018-07-16T16:44:46.957 回答
1

在没有预编译头文件的情况下编译即使是一个小项目也可能需要很长时间,因为任何项目都间接包含许多 SDK 和标准库头文件。所以是的,您需要这些文件,不,删除它们不会得到任何有用的东西。没有它们,您的项目将非常缓慢地编译,这是您将得到的唯一结果。

如果您还不知道这一点 - 标准头文件(如“windows.h”或“stdlib.h”)的所有包含都必须在“stdafx.h”中。这样,标准头文件将不会在每个项目构建(以及每个项目文件)上重新编译。

于 2018-07-16T16:51:54.870 回答