我目前正在更新一个古老的程序,这是最后一次编译与visual 2008。为了最新的windows (10.0.15063.0),我正在将它(.lib项目)更新到VisualStudio2017,但是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是什么?)新包含的。
那么,如何将外部库指向使用一个符号定义或另一个符号定义?
任何帮助都是非常感谢的。
发布于 2017-08-30 10:44:15
出现此问题是因为最近的标准引入了::std::byte
和::byte
类型,这将与rpcndr.h
中定义的byte
类型发生冲突。
// cstddef
enum class byte : unsigned char {};
// rpcndr.h
typedef unsigned char byte;
但这并不是windows的唯一问题,它们还引入了与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
请注意,这种方法意味着用户代码从不使用windows头中的byte
、min
和max
。
此外,byte
可能与其他第三方库发生冲突。
发布于 2019-02-05 20:53:00
对于Visual,可以通过将预处理器值
_HAS_STD_BYTE
定义为0
来关闭此行为。
取自这篇文章。
https://stackoverflow.com/questions/45957830
复制相似问题