首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >为cstddef和rpcndr.h抛出不明确的字节

为cstddef和rpcndr.h抛出不明确的字节
EN

Stack Overflow用户
提问于 2017-08-30 10:20:04
回答 2查看 4.5K关注 0票数 6

我目前正在更新一个古老的程序,这是最后一次编译与visual 2008。为了最新的windows (10.0.15063.0),我正在将它(.lib项目)更新到VisualStudio2017,但是gdiplus库会抛出一个模糊的符号错误。更具体而言:

代码语言:javascript
运行
复制
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是什么?)新包含的。

那么,如何将外部库指向使用一个符号定义或另一个符号定义?

任何帮助都是非常感谢的。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-08-30 10:44:15

出现此问题是因为最近的标准引入了::std::byte::byte类型,这将与rpcndr.h中定义的byte类型发生冲突。

代码语言:javascript
运行
复制
// cstddef
enum class byte : unsigned char {};

// rpcndr.h
typedef unsigned char byte;

但这并不是windows的唯一问题,它们还引入了与min内容冲突的max<limits>宏(双工工所要求的)。

因此,解决方法应该小心地控制如何包含windows和gdi +标头,如下所示:

代码语言:javascript
运行
复制
//  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头中的byteminmax

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

票数 11
EN

Stack Overflow用户

发布于 2019-02-05 20:53:00

对于Visual,可以通过将预处理器值_HAS_STD_BYTE定义为0来关闭此行为。

取自这篇文章

票数 9
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45957830

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档