我目前正在更新一个古老的程序,最后与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是?)。
所以,我怎么能指向使用一个符号定义或其他外部库?
任何帮助是极大的赞赏。
发生此问题,因为最新的标准出台::std::byte
和::byte
类型将与在byte
定义rpcndr.h
类型冲突:
// cstddef
enum class byte : unsigned char {};
// rpcndr.h
typedef unsigned char byte;
但是,这是不是与Windows头唯一的问题,他们还引入了(由gdiplus要求)min
和max
宏与<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
注意,这种方法意味着用户代码从不使用byte
,min
和max
从Windows SDK头。
此外byte
可以与其他第三方库发生冲突。
对于Visual Studio,这种行为可以通过定义预处理值
_HAS_STD_BYTE
到0
被关闭。
从this article拍摄。