c++ - 如何修复 Element <PrecompiledHeader> 在 C++ 中有无效值 "/Yu"错误?

标签 c++

我正在自学,我想知道如何在我的控制台应用程序中使用预编译 header 。我已经阅读了很多指南,似乎我做的一切都是正确的,但我仍然会出错。

我使用 visual studio 2019。所以我有 main.cpp 文件,其中包含使用的代码和我想预编译的库。我创建了一个名为 stdafx.h 的文件,并在其中包含了所有库。然后我创建了仅包含 stdafx.h 的 stdafx.cpp。在 stdafx.cpp 预编译器 header 的项目属性中是/Yc,对于 main 来说是/Yu。

stdafx.h:

#include <iostream>
#include <cmath>

stdafx.cpp:

#include "stdafx.h"

主要.cpp:

#include "stdafx.h"
using namespace std;

double getInfoFromUser()
{
    double info;
    cin >> info;
    return info;
}

double computeSqrtDiscriminant(double A, double B, double C)
{
    double i{ sqrt(pow(B, 2) - 4 * A * C) };
    return i;
}

double computeX1(double A, double B, double SqrtDiscriminant)
{
    double X1{ (-B + SqrtDiscriminant) / (2 * A) };
    return X1;
}

double computeX2(double A, double B, double SqrtDiscriminant)
{
    double X2{ (-B - SqrtDiscriminant) / (2 * A) };
    return X2;
}

void computePoint1(double X1, double K, double M)
{
    double Y{ X1 * K + M };
    cout << "Первая точка пересечения:[" << X1 << "," << Y << "]" << endl;
}

void computePoint2(double X2, double K, double M)
{
    double Y{ X2 * K + M };
    cout << "Вторая точка пересечения:[" << X2 << "," << Y << "]";
}

double equateX(double B, double K)
{
    double NewB{ B - K };
    return NewB;
}

double equateC(double C, double M)
{
    double NewC{ C - M };
    return NewC;
}

int main()
{
    setlocale(LC_ALL, "rus");
    cout << "Введите уравнение параболы (aх^2+bx+c=0):" << endl;
    cout << "Введите a:";
    double A{ getInfoFromUser() };
    cout << "Введите b:";
    double B{ getInfoFromUser() };
    cout << "Введите c:";
    double C{ getInfoFromUser() };
    cout << "Введите уравнение прямой (Kx+m)" << endl;
    cout << "Введите k:";
    double K{ getInfoFromUser() };
    cout << "Введите m:";
    double M{ getInfoFromUser() };
    B = equateX(B, K);
    C = equateC(C, M);
    double SqrtDiscriminant = computeSqrtDiscriminant(A, B, C);
    double X1{ computeX1(A, B, SqrtDiscriminant) };
    double X2{ computeX2(A, B, SqrtDiscriminant) };
    computePoint1(X1, K, M);
    if (X1 != X2)
    {
        computePoint2(X2, K, M);
    }
    return 0;
}

main.cpp 即使没有预编译头文件也能很好地编译,但我想学习如何使用它们。如果使用预编译头文件编译,我会得到以下两个错误: 错误:元素具有无效值“/Yu”。 错误 MSB6011:в задачу Microsoft.Build.CPPTasks.CL переданы недопустимые параметры。(我来自乌克兰,所以我使用俄语本地化)。

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup Label="ProjectConfigurations">
    <ProjectConfiguration Include="Debug|Win32">
      <Configuration>Debug</Configuration>
      <Platform>Win32</Platform>
    </ProjectConfiguration>
    <ProjectConfiguration Include="Release|Win32">
      <Configuration>Release</Configuration>
      <Platform>Win32</Platform>
    </ProjectConfiguration>
    <ProjectConfiguration Include="Debug|x64">
      <Configuration>Debug</Configuration>
      <Platform>x64</Platform>
    </ProjectConfiguration>
    <ProjectConfiguration Include="Release|x64">
      <Configuration>Release</Configuration>
      <Platform>x64</Platform>
    </ProjectConfiguration>
  </ItemGroup>
  <PropertyGroup Label="Globals">
    <VCProjectVersion>16.0</VCProjectVersion>
    <ProjectGuid>{9F202045-E5DB-4685-9FCD-AFA97F3F750B}</ProjectGuid>
    <Keyword>Win32Proj</Keyword>
    <RootNamespace>ConsoleApplicationParabolaIpryama</RootNamespace>
    <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
    <ProjectName>ParabolaPryamaya</ProjectName>
  </PropertyGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
    <ConfigurationType>Application</ConfigurationType>
    <UseDebugLibraries>true</UseDebugLibraries>
    <PlatformToolset>v142</PlatformToolset>
    <CharacterSet>Unicode</CharacterSet>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
    <ConfigurationType>Application</ConfigurationType>
    <UseDebugLibraries>false</UseDebugLibraries>
    <PlatformToolset>v142</PlatformToolset>
    <WholeProgramOptimization>true</WholeProgramOptimization>
    <CharacterSet>Unicode</CharacterSet>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
    <ConfigurationType>Application</ConfigurationType>
    <UseDebugLibraries>true</UseDebugLibraries>
    <PlatformToolset>v142</PlatformToolset>
    <CharacterSet>Unicode</CharacterSet>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
    <ConfigurationType>Application</ConfigurationType>
    <UseDebugLibraries>false</UseDebugLibraries>
    <PlatformToolset>v142</PlatformToolset>
    <WholeProgramOptimization>true</WholeProgramOptimization>
    <CharacterSet>Unicode</CharacterSet>
  </PropertyGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
  <ImportGroup Label="ExtensionSettings">
  </ImportGroup>
  <ImportGroup Label="Shared">
  </ImportGroup>
  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
  </ImportGroup>
  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
  </ImportGroup>
  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
  </ImportGroup>
  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
  </ImportGroup>
  <PropertyGroup Label="UserMacros" />
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    <LinkIncremental>true</LinkIncremental>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
    <LinkIncremental>true</LinkIncremental>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    <LinkIncremental>false</LinkIncremental>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
    <LinkIncremental>false</LinkIncremental>
  </PropertyGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    <ClCompile>
      <PrecompiledHeader>
      </PrecompiledHeader>
      <WarningLevel>Level3</WarningLevel>
      <Optimization>Disabled</Optimization>
      <SDLCheck>true</SDLCheck>
      <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <ConformanceMode>true</ConformanceMode>
    </ClCompile>
    <Link>
      <SubSystem>Console</SubSystem>
      <GenerateDebugInformation>true</GenerateDebugInformation>
    </Link>
  </ItemDefinitionGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
    <ClCompile>
      <PrecompiledHeader>
      </PrecompiledHeader>
      <WarningLevel>Level3</WarningLevel>
      <Optimization>Disabled</Optimization>
      <SDLCheck>true</SDLCheck>
      <PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <ConformanceMode>true</ConformanceMode>
    </ClCompile>
    <Link>
      <SubSystem>Console</SubSystem>
      <GenerateDebugInformation>true</GenerateDebugInformation>
    </Link>
  </ItemDefinitionGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    <ClCompile>
      <PrecompiledHeader>
      </PrecompiledHeader>
      <WarningLevel>Level3</WarningLevel>
      <Optimization>MaxSpeed</Optimization>
      <FunctionLevelLinking>true</FunctionLevelLinking>
      <IntrinsicFunctions>true</IntrinsicFunctions>
      <SDLCheck>true</SDLCheck>
      <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <ConformanceMode>true</ConformanceMode>
    </ClCompile>
    <Link>
      <SubSystem>Console</SubSystem>
      <EnableCOMDATFolding>true</EnableCOMDATFolding>
      <OptimizeReferences>true</OptimizeReferences>
      <GenerateDebugInformation>true</GenerateDebugInformation>
    </Link>
  </ItemDefinitionGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
    <ClCompile>
      <PrecompiledHeader>
      </PrecompiledHeader>
      <WarningLevel>Level3</WarningLevel>
      <Optimization>MaxSpeed</Optimization>
      <FunctionLevelLinking>true</FunctionLevelLinking>
      <IntrinsicFunctions>true</IntrinsicFunctions>
      <SDLCheck>true</SDLCheck>
      <PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <ConformanceMode>true</ConformanceMode>
    </ClCompile>
    <Link>
      <SubSystem>Console</SubSystem>
      <EnableCOMDATFolding>true</EnableCOMDATFolding>
      <OptimizeReferences>true</OptimizeReferences>
      <GenerateDebugInformation>true</GenerateDebugInformation>
    </Link>
  </ItemDefinitionGroup>
  <ItemGroup>
    <ClCompile Include="main.cpp">
      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">/Yu</PrecompiledHeader>
      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">/Yu</PrecompiledHeader>
      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">/Yu</PrecompiledHeader>
      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">/Yu</PrecompiledHeader>
    </ClCompile>
    <ClCompile Include="stdafx.cpp">
      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">/Yc</PrecompiledHeader>
      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">/Yc</PrecompiledHeader>
      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">/Yc</PrecompiledHeader>
      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">/Yc</PrecompiledHeader>
    </ClCompile>
  </ItemGroup>
  <ItemGroup>
    <ClInclude Include="stdafx.h" />
  </ItemGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
  <ImportGroup Label="ExtensionTargets">
  </ImportGroup>
</Project>

最佳答案

所以问题是我在文件的属性中手动输入了/Yu 和/Yc,尽管右上角有 dropbox-box。如果您使用保管箱,问题就会消失。

关于c++ - 如何修复 Element <PrecompiledHeader> 在 C++ 中有无效值 "/Yu"错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56807205/

相关文章:

c++ - 调试 __do_global_dtors_aux 以查找代码位置

c++ - C++类图和{query}

c++ - 与 ‘operator<<’ 不匹配(操作数类型为 ‘std::ostream’ {aka ‘std::basic_ostream<char>’ } 和 ‘const std::type_index’ )

c++ - 使用可能抛出的表达式初始化 const 变量的推荐方法

c++ - 如何将字符串作为二进制文件写入文件?

c++ - header 中的类模板

c++ - 为什么这段代码编译时没有提示构造函数?

c++ - 从 vector 中获取超出范围的元素

c++ - 函数原型(prototype)返回错误

c++ - 模板名称和模板id的区别