Kas*_*jær 2 c++ gdi+ visual-studio-2017
我当前正在更新一个上次用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'
Run Code Online (Sandbox Code Playgroud)
不幸的是,我在这个问题上发现的标准尝试是假设歧义错误是我直接造成的,而不是Visual Studio的新包含(我理解cstddef是什么?)。
那么,如何将外部库指向使用一个符号定义或另一个符号定义呢?
任何帮助是极大的赞赏。
发生此问题的原因是最近引入了标准,::std::byte并且::byte类型将与byte在中定义的类型冲突rpcndr.h:
// cstddef
enum class byte : unsigned char {};
// rpcndr.h
typedef unsigned char byte;
Run Code Online (Sandbox Code Playgroud)
但这不是Windows标头的唯一问题,它们还引入了与内容冲突的min和max宏(gdiplus要求)<limits>。
因此,解决方法是仔细控制如何包括windows和gdi plus标头,如下所示:
// 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
Run Code Online (Sandbox Code Playgroud)
注意,这种方法意味着用户代码永远不会使用byte,min并max从Windows SDK头。
也byte可能与其他第三方库发生冲突。
| 归档时间: |
|
| 查看次数: |
1042 次 |
| 最近记录: |