gdipluspath为cstddef和rpcndr.h抛出不明确的字节 [英] gdipluspath throws ambiguous byte for cstddef and rpcndr.h
问题描述
我当前正在更新一个上次用Visual Studio 2008编译的古老程序.我正在将它(.lib项目)更新到Visual Studio 2017,以获取最新的Windows sdk(10.0.15063.0),但是,gdiplus库抛出了一个错误.含糊不清的符号错误. 更具体地说:
I am currently updating an ancient program which was last compiled with visual studio 2008. I am updating it (.lib project) to visual studio 2017 for the newest windows sdk (10.0.15063.0), however, the gdiplus library throws an ambiguous symbol error. More specifically:
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是什么?).
The standard attempts that I have found at this issue unfortunately suppose that the ambiguity error is made by me directly, and not by a new inclusion by visual studio (Which is what I understand cstddef to be?).
那么,如何将外部库指向使用一个符号定义或另一个符号定义呢?
So how can I point an external library towards using one symbol definition or the other?
非常感谢您的帮助.
推荐答案
之所以会出现此问题,是因为最近的标准引入了::std::byte
和::byte
类型,它们将与rpcndr.h
中定义的byte
类型发生冲突:
This problem occurs because recent standard introduced ::std::byte
and ::byte
types which will clash with byte
type defined in rpcndr.h
:
// cstddef
enum class byte : unsigned char {};
// rpcndr.h
typedef unsigned char byte;
但这不是Windows标头的唯一问题,它们还引入了与<limits>
内容冲突的min
和max
宏(gdiplus要求).
But that is not the only problem with windows headers, they also introduce min
and max
macros (required by gdiplus) that clash with <limits>
content.
因此,解决方法将是仔细控制如何包括Windows和gdi以及标头,如下所示:
So the workaround would be carefully control how windows and gdi plus headers are included, like this:
// 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
请注意,这种方法意味着用户代码从不使用Windows sdk标头中的byte
,min
和max
.
Note that this approach implies that user code never uses byte
, min
and max
from windows sdk headers.
byte
也可能与其他第三方库发生冲突.
Also byte
may clash with other third-party libraries.
这篇关于gdipluspath为cstddef和rpcndr.h抛出不明确的字节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!