warning C4003: “max”宏的实参不足

本文解决MFC项目引入PDFium后的编译错误,特别是关于safe_conversions_impl.h文件中的宏定义与标准库函数冲突的问题。通过修改源代码中的std::numeric_limits::max()调用来避免与Windows头文件中max宏的冲突。

下载pdfium编译成功后,想在一mfc单文档里面引用,

报错:1>e:\hbj\test3\test0915\test10102\third_party\numerics\safe_conversions_impl.h(154): warning C4003: “max”宏的实参不足

...

1>e:\hbj\test3\test0915\test10102\third_party\numerics\safe_conversions_impl.h(183): error C2589: “(”:“::”右边的非法标记

1>e:\hbj\test3\test0915\test10102\third_party\numerics\safe_conversions_impl.h(183): error C2059: 语法错误:“::”
1>e:\hbj\test3\test0915\test10102\third_party\numerics\safe_conversions_impl.h(183): error C2143: 语法错误 : 缺少“(”(在“::”的前面)
1>e:\hbj\test3\test0915\test10102\third_party\numerics\safe_conversions_impl.h(183): error C2059: 语法错误:“)”

源代码:safe_conversions_impl.h

template <typename Dst, typename Src>
struct DstRangeRelationToSrcRangeImpl<Dst,
                                      Src,
                                      INTEGER_REPRESENTATION_SIGNED,
                                      INTEGER_REPRESENTATION_SIGNED,
                                      NUMERIC_RANGE_NOT_CONTAINED> {
  static RangeConstraint Check(Src value) {

    return std::numeric_limits<Dst>::is_iec559
        ? GetRangeConstraint(value <= std::numeric_limits<Dst>::max(),
                                    value >= -std::numeric_limits<Dst>::max())
               : GetRangeConstraint(value <= std::numeric_limits<Dst>::max(),
                                    value >= std::numeric_limits<Dst>::min());
  }
};

原因:

因为Windef.h中定义了
#ifndef max
#define max(a,b)            (((a) > (b)) ? (a) : (b))
#endif

vc的max宏和std::numeric_limits<>max()函数冲突

解决:1.把std::numeric_limits<>max()用括号括起来避免和windows定义的宏混淆,例如(std::numeric_limits<Dst>::max)()

2.为了解决这个问题,Visual C++ 定义了另外两个功能相同的模板:_cpp_min() 和 _cpp_max()。我们可以用它们来代替std::min() 和 std::max()(未验证)

参考:http://blog.chinaunix.net/uid-17102734-id-2830143.html

http://blog.youkuaiyun.com/xidianzhimeng/article/details/21181279

http://blog.163.com/fleeting_ash/blog/static/663410862009310113424930/


生成开始于 16:50... 1>------ 已启动生成: 项目: ScriptGeneratorUbtPlugin.ubtplugin, 配置: Development Any CPU ------ 2>------ 已跳过“生成”: 项目: UE5, 配置: BuiltWithUnrealBuildTool Win64 ------ 2>没有为此解决方案配置选中要生成的项目 3>------ 已启动生成: 项目: UE5Rules, 配置: Development Any CPU ------ 4>------ 已启动生成: 项目: SZJ_S_09, 配置: Development_Editor x64 ------ 5>------ 已启动生成: 项目: BuildGraph.Automation, 配置: Development Any CPU ------ 6>------ 已启动生成: 项目: AutomationScripts.Automation, 配置: Development Any CPU ------ 4>Using bundled DotNet SDK version: 6.0.302 4>Running UnrealBuildTool: dotnet "..\..\Engine\Binaries\DotNET\UnrealBuildTool\UnrealBuildTool.dll" SZJ_S_09Editor Win64 Development -Project="Z:\SZJ\Task\Sunmb\UE\Back\SZJ_S_13_T0\SZJ_S_09.uproject" -WaitMutex -FromMsBuild 4>Log file: C:\Users\Administrator\AppData\Local\UnrealBuildTool\Log.txt 4>Creating makefile for SZJ_S_09Editor (command line arguments changed) 1>ScriptGeneratorUbtPlugin.ubtplugin -> D:\UE_5.3\Engine\Binaries\DotNET\UnrealBuildTool\Plugins\ScriptGeneratorUbtPlugin\ScriptGeneratorUbtPlugin.dll 5>D:\UE_5.3\Engine\Source\Programs\AutomationTool\BuildGraph\BgScriptReader.cs(1640,37,1640,42): error CS8604: “void HashSet<string>.UnionWith(IEnumerable<string> other)”中的形参“other”可能传入 null 引用实参。 5>已完成生成项目“BuildGraph.Automation.csproj”的操作 - 失败。 3>D:\UE_5.3\Engine\Source\ThirdParty\Windows\VisualStudioDTE\VisualStudioDTE.Build.cs(55,26,55,140): warning CA1416: 可在所有平台上访问此调用站点。"Registry.GetValue(string, string?, object?)" 仅在 'windows' 上受支持。 (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416) 3>D:\UE_5.3\Engine\Plugins\Developer\VisualStudioCodeSourceCodeAccess\Source\VisualStudioCodeSourceCodeAccess\VisualStudioCodeSourceCodeAccess.Build.cs(42,27,42,120): warning CA1416: 可在所有平台上访问此调用站点。"RegistryKey.OpenSubKey(string)" 仅在 'windows' 上受支持。 (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416) 3>D:\UE_5.3\Engine\Plugins\Developer\VisualStudioCodeSourceCodeAccess\Source\VisualStudioCodeSourceCodeAccess\VisualStudioCodeSourceCodeAccess.Build.cs(42,51,42,75): warning CA1416: 可在所有平台上访问此调用站点。"RegistryHive.ClassesRoot" 仅在 'windows' 上受支持。 (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416) 3>D:\UE_5.3\Engine\Plugins\Developer\VisualStudioCodeSourceCodeAccess\Source\VisualStudioCodeSourceCodeAccess\VisualStudioCodeSourceCodeAccess.Build.cs(42,27,42,101): warning CA1416: 可在所有平台上访问此调用站点。"RegistryKey.OpenBaseKey(RegistryHive, RegistryView)" 仅在 'windows' 上受支持。 (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416) 3>D:\UE_5.3\Engine\Plugins\Developer\VisualStudioCodeSourceCodeAccess\Source\VisualStudioCodeSourceCodeAccess\VisualStudioCodeSourceCodeAccess.Build.cs(42,77,42,100): warning CA1416: 可在所有平台上访问此调用站点。"RegistryView.Registry32" 仅在 'windows' 上受支持。 (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416) 3>D:\UE_5.3\Engine\Source\ThirdParty\NVIDIA\Rivermax\RivermaxLib.build.cs(17,33,17,142): warning CA1416: 可在所有平台上访问此调用站点。"Registry.GetValue(string, string?, object?)" 仅在 'windows' 上受支持。 (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416) 3>D:\UE_5.3\Engine\Source\ThirdParty\Windows\XInput\XInput.Build.cs(27,10,27,92): warning CA1416: 可在所有平台上访问此调用站点。"WindowsExports.TryGetWindowsSdkDir(string, out Version?, out DirectoryReference?)" 仅在 'windows' 上受支持。 (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416) 3>D:\UE_5.3\Engine\Source\Runtime\Core\Core.Build.cs(211,36,211,146): warning CA1416: 可在所有平台上访问此调用站点。"Registry.GetValue(string, string?, object?)" 仅在 'windows' 上受支持。 (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416) 4>Building SZJ_S_09Editor... 4>Using Visual Studio 2022 14.36.32548 toolchain (C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532) and Windows 10.0.26100.0 SDK (C:\Program Files (x86)\Windows Kits\10). 4>[Upgrade] 4>[Upgrade] Using backward-compatible include order. The latest version of UE has changed the order of includes, which may require code changes. The current setting is: 4>[Upgrade] IncludeOrderVersion = EngineIncludeOrderVersion.Unreal5_0 4>[Upgrade] Suppress this message by setting 'IncludeOrderVersion = EngineIncludeOrderVersion.Latest;' in SZJ_S_09Editor.Target.cs. 4>[Upgrade] Alternatively you can set this to 'EngineIncludeOrderVersion.Latest' to always use the latest include order. This will potentially cause compile errors when integrating new versions of the engine. 4>[Upgrade] 4>Determining max actions to execute in parallel (8 physical cores, 16 logical cores) 4> Executing up to 8 processes, one per physical core 4>------ Building 9 action(s) started ------ 3>UE5Rules -> D:\UE_5.3\Engine\Intermediate\Build\BuildRulesProjects\UE5Rules\bin\Development\UE5Rules.dll 3>已完成生成项目“UE5Rules.csproj”的操作。 7>------ 已启动生成: 项目: UE5ProgramRules, 配置: Development Any CPU ------ 4>[1/9] Resource Default.rc2 6>D:\UE_5.3\Engine\Source\Programs\AutomationTool\Scripts\CheckForHacks.cs(87,26,87,45): error CA2017: 日志记录消息模板中所提供参数的数量与已命名占位符的数量不匹配 (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2017) 6>已完成生成项目“AutomationScripts.Automation.csproj”的操作 - 失败。 7>D:\UE_5.3\Engine\Source\Programs\Shared\EpicGames.Perforce.Native\DotNetPerforceLib.Target.cs(5,14,5,37): warning CA1050: 在命名空间中声明类型 (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1050) 7>D:\UE_5.3\Engine\Source\Programs\Shared\EpicGames.Perforce.Native\DotNetPerforceLib.Build.cs(5,14,5,31): warning CA1050: 在命名空间中声明类型 (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1050) 7>UE5ProgramRules -> D:\UE_5.3\Engine\Intermediate\Build\BuildRulesProjects\UE5ProgramRules\bin\Development\UE5ProgramRules.dll 7>已完成生成项目“UE5ProgramRules.csproj”的操作。 8>------ 已启动生成: 项目: MarketplaceRules, 配置: Development Any CPU ------ 9>------ 已启动生成: 项目: CookedEditor.Automation, 配置: Development Any CPU ------ 8>MarketplaceRules -> D:\UE_5.3\Engine\Intermediate\Build\BuildRulesProjects\MarketplaceRules\bin\Development\MarketplaceRules.dll 10>------ 已启动生成: 项目: SZJ_S_09ModuleRules, 配置: Development Any CPU ------ 10>SZJ_S_09ModuleRules -> Z:\SZJ\Task\Sunmb\UE\Back\SZJ_S_13_T0\Intermediate\Build\BuildRulesProjects\SZJ_S_09ModuleRules\bin\Development\SZJ_S_09ModuleRules.dll 4>[2/9] Compile [x64] SharedPCH.Engine.Cpp20.InclOrderUnreal5_0.cpp 4>[3/9] Compile [x64] SZJ_S_09.init.gen.cpp 4>[4/9] Compile [x64] SZJ_S_09.cpp 4>[5/9] Compile [x64] MyObject.cpp 4>[6/9] Compile [x64] MyObject.gen.cpp 4>[7/9] Link [x64] UnrealEditor-SZJ_S_09.lib 4> 正在创建库 Z:\SZJ\Task\Sunmb\UE\Back\SZJ_S_13_T0\Intermediate\Build\Win64\x64\UnrealEditor\Development\SZJ_S_09\UnrealEditor-SZJ_S_09.lib 和对象 Z:\SZJ\Task\Sunmb\UE\Back\SZJ_S_13_T0\Intermediate\Build\Win64\x64\UnrealEditor\Development\SZJ_S_09\UnrealEditor-SZJ_S_09.exp 4>[8/9] Link [x64] UnrealEditor-SZJ_S_09.dll 4> 正在创建库 Z:\SZJ\Task\Sunmb\UE\Back\SZJ_S_13_T0\Intermediate\Build\Win64\x64\UnrealEditor\Development\SZJ_S_09\UnrealEditor-SZJ_S_09.sup.lib 和对象 Z:\SZJ\Task\Sunmb\UE\Back\SZJ_S_13_T0\Intermediate\Build\Win64\x64\UnrealEditor\Development\SZJ_S_09\UnrealEditor-SZJ_S_09.sup.exp 4>[9/9] WriteMetadata SZJ_S_09Editor.target 4>Total time in Parallel executor: 71.64 seconds 4>Total execution time: 75.48 seconds ========== 生成: 7 成功,2 失败,39 最新,1 已跳过 ========== ========== 生成 于 16:51 完成,耗时 01:17.851 分钟 ========== Visual Studio 已加速 17 个项目,正在复制 38 个文件。请参阅 https://aka.ms/vs-build-acceleration。
最新发布
09-27
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值