gdipluspath会因cstddef和rpcndr.h暧昧字节

问题描述 投票:1回答:2

我目前正在更新一个古老的程序,最后与Visual Studio编译2008年我在它(.LIB项目)更新到Visual Studio 2017年最新的Windows SDK中(10.0.15063.0),然而,gdiplus库会引发不明确的符号错误。进一步来说:

3>c:\program files (x86)\windows kits\10\include\10.0.15063.0\um\GdiplusPath.h(145): error C2872: 'byte': ambiguous symbol
3>c:\program files (x86)\windows kits\10\include\10.0.15063.0\shared\rpcndr.h(191): note: could be 'unsigned char byte'
3>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\include\cstddef(15): note: or 'std::byte'

我已经在这个问题上所存在的标准尝试不幸假设模糊误差是由我直接制成,而不是由一个新的包含由Visual Studio(这是我的理解cstddef是?)。

所以,我怎么能指向使用一个符号定义或其他外部库?

任何帮助是极大的赞赏。

c++ visual-studio-2017 gdi+
2个回答
6
投票

发生此问题,因为最新的标准出台::std::byte::byte类型将与在byte定义rpcndr.h类型冲突:

// cstddef
enum class byte : unsigned char {};

// rpcndr.h
typedef unsigned char byte;

但是,这是不是与Windows头唯一的问题,他们还引入了(由gdiplus要求)minmax宏与<limits>内容冲突。

因此,解决方法是仔细对照了Windows和GDI加头都包括在内,像这样的:

//  global compilation flag configuring windows sdk headers
//  preventing inclusion of min and max macros clashing with <limits>
#define NOMINMAX 1

//  override byte to prevent clashes with <cstddef>
#define byte win_byte_override

#include <Windows.h> // gdi plus requires Windows.h
// ...includes for other windows header that may use byte...

//  Define min max macros required by GDI+ headers.
#ifndef max
#define max(a,b) (((a) > (b)) ? (a) : (b))
#else
#error max macro is already defined
#endif
#ifndef min
#define min(a,b) (((a) < (b)) ? (a) : (b))
#else
#error min macro is already defined
#endif

#include <gdiplus.h>

//  Undefine min max macros so they won't collide with <limits> header content.
#undef min
#undef max

//  Undefine byte macros so it won't collide with <cstddef> header content.
#undef byte

注意,这种方法意味着用户代码从不使用byteminmax从Windows SDK头。

此外byte可以与其他第三方库发生冲突。


1
投票

对于Visual Studio,这种行为可以通过定义预处理值_HAS_STD_BYTE0被关闭。

this article拍摄。

© www.soinside.com 2019 - 2024. All rights reserved.