wxWidgets 和 boost::p roperty_tree 之间的冲突

Conflict between wxWidgets and boost::property_tree

本文关键字:之间 tree 冲突 roperty boost wxWidgets      更新时间:2023-10-16

我想在wxWidgets应用程序中使用boost::p roperty_tree。

但是当我添加行时

#include <boost/property_tree/ptree.hpp>

到一个简单的wxWidgets,我突然得到编译错误:

||=== Build: Release in pulley_client_gui (compiler: GNU GCC Compiler) ===|
C:UsersJamescodewxWidgets-3.0.1includewxmswwinundef.h||In function 'HWND__* CreateDialog(HINSTANCE, LPCTSTR, HWND, DLGPROC)':|
C:UsersJamescodewxWidgets-3.0.1includewxmswwinundef.h|38|error: cannot convert 'LPCTSTR {aka const char*}' to 'LPCWSTR {aka const wchar_t*}' for argument '2' to 'HWND__* CreateDialogParamW(HINSTANCE, LPCWSTR, HWND, DLGPROC, LPARAM)'|
C:UsersJamescodewxWidgets-3.0.1includewxmswwinundef.h||In function 'HFONT__* CreateFont(int, int, int, int, int, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, LPCTSTR)':|
C:UsersJamescodewxWidgets-3.0.1includewxmswwinundef.h|69|error: cannot convert 'LPCTSTR {aka const char*}' to 'LPCWSTR {aka const wchar_t*}' for argument '14' to 'HFONT__* CreateFontW(int, int, int, int, int, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, LPCWSTR)'|
C:UsersJamescodewxWidgets-3.0.1includewxmswwinundef.h||In function 'HWND__* CreateWindow(LPCTSTR, LPCTSTR, DWORD, int, int, int, int, HWND, HMENU, HINSTANCE, LPVOID)':|
C:UsersJamescodewxWidgets-3.0.1includewxmswwinundef.h|94|error: cannot convert 'LPCTSTR {aka const char*}' to 'LPCWSTR {aka const wchar_t*}' for argument '2' to 'HWND__* CreateWindowExW(DWORD, LPCWSTR, LPCWSTR, DWORD, int, int, int, int, HWND, HMENU, HINSTANCE, LPVOID)'|
C:UsersJamescodewxWidgets-3.0.1includewxmswwinundef.h||In function 'HMENU__* LoadMenu(HINSTANCE, LPCTSTR)':|
C:UsersJamescodewxWidgets-3.0.1includewxmswwinundef.h|111|error: cannot convert 'LPCTSTR {aka const char*}' to 'LPCWSTR {aka const wchar_t*}' for argument '2' to 'HMENU__* LoadMenuW(HINSTANCE, LPCWSTR)'|
C:UsersJamescodewxWidgets-3.0.1includewxmswwinundef.h||In function 'HICON__* LoadIcon(HINSTANCE, LPCTSTR)':|
C:UsersJamescodewxWidgets-3.0.1includewxmswwinundef.h|311|error: cannot convert 'LPCTSTR {aka const char*}' to 'LPCWSTR {aka const wchar_t*}' for argument '2' to 'HICON__* LoadIconW(HINSTANCE, LPCWSTR)'|
C:UsersJamescodewxWidgets-3.0.1includewxmswwinundef.h||In function 'HBITMAP__* LoadBitmap(HINSTANCE, LPCTSTR)':|
C:UsersJamescodewxWidgets-3.0.1includewxmswwinundef.h|324|error: cannot convert 'LPCTSTR {aka const char*}' to 'LPCWSTR {aka const wchar_t*}' for argument '2' to 'HBITMAP__* LoadBitmapW(HINSTANCE, LPCWSTR)'|
||=== Build failed: 6 error(s), 0 warning(s) (0 minute(s), 3 second(s)) ===|

这似乎表明 wxWidgets 方法无法再处理 UTF8 参数,转换为 UTF16 的能力已被 boost 头文件破坏。

似乎UNICODE定义不一致,即当 Boost 标头中包含 <windows.h> 时定义(或不定义),而当包含 wxWidgets 标头时未定义(或正在)。

为了防止这种情况发生,建议的解决方案是在 make 或项目文件中定义UNICODE,以便在命令行上定义它。您可能已经在那里定义了_UNICODE(如果使用 MSVS 项目),但这只会影响 CRT 标头,并且您也需要UNICODE才能<windows.h>

找到了解决方法。 如果我在 wxWidgets 标头之后包含提升标头,则编译成功。