首页 > 解决方案 > Visual Studio 2017 - 通过命令行和 MSBuild 构建 - 缺少 stdafx.h

问题描述

我有一个我通常在 Visual Studio 中编译的 sln 文件

现在我尝试在命令行上编译我的项目

我不使用任何预编译的头文件,所以在命令行上感觉缺少一些东西,因为就像我一样

MSBuild.exe myproject.sln

我得到错误

unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"'

就像项目的配置没有被读取一样

设置图片

试图强制一个配置/平台,我明白了

c:\myproject>"P:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\MSBuild".exe game2D_sdl.sln /p:Configuration=Debug /p:Platform=Win32
Microsoft (R) Build Engine version 15.6.82.30579 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.

Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
Build started 1/03/2019 18:08:47.
Project "c:\myproject\game2D_sdl.sln" on node 1 (default targets).
c:\myproject\game2D_sdl.sln.metaproj : error MSB4126: The specified solution configuration "Debug|Win32" is invalid. Please specify a valid solution configuration using the Configuration an
d Platform properties (e.g. MSBuild.exe Solution.sln /p:Configuration=Debug /p:Platform="Any CPU") or leave those properties blank to use the default solution configuration. [c:\myproject\g
ame2D_sdl.sln]
Done Building Project "c:\myproject\game2D_sdl.sln" (default targets) -- FAILED.

我在所有平台上都禁用了 PCH,只是在不强制平台的情况下构建,我得到包含错误

c:\myproject>"P:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\MSBuild".exe game2D_sdl.sln
Microsoft (R) Build Engine version 15.6.82.30579 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.

Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
Build started 1/03/2019 18:13:52.
Project "c:\myproject\game2D_sdl.sln" on node 1 (default targets).
ValidateSolutionConfiguration:
  Building solution configuration "Debug|x64".
Project "c:\myproject\game2D_sdl.sln" (1) is building "c:\myproject\game2D_sdl\game2D_sdl.vcxproj" (2) on node 1 (default targets).
InitializeBuildStatus:
  Touching "x64\Debug\game2D_sdl.tlog\unsuccessfulbuild".
ClCompile:
  P:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.13.26128\bin\HostX86\x64\CL.exe /c /ZI /nologo /W3 /WX- /diagnostics:classic /sdl /Od /D _DEBUG /D _CONSOLE /D _UNICOD
  E /D UNICODE /Gm- /EHsc /RTC1 /MDd /GS /fp:precise /permissive- /Zc:wchar_t /Zc:forScope /Zc:inline /Fo"x64\Debug\\" /Fd"x64\Debug\vc141.pdb" /Gd /TP /FC /errorReport:queue animations.cpp audio.cpp
   box.cpp .... animations.cpp .....
c:\myproject\game2d_sdl\game2d_sdl.h(13): fatal error C1083: Cannot open include file: 'nlohmann/json.hpp': No such file or directory [c:\myproject\game2D_sdl\game2D_sdl.vcxproj]
  audio.cpp

我如何设法正确编译项目?谢谢

标签: c++visual-studioprecompiled-headers

解决方案


关闭预编译的头文件:

Project Properties -> C++ -> Precompiled Headers 将 Precompiled Header 设置为“Not Using Precompiled Header”。

您可能想阅读以下答案: Visual Studio 中使用什么“stdafx.h”?


推荐阅读