简体   繁体   中英

Conflict between wxWidgets and boost::property_tree

I'd like to use boost::property_tree in a wxWidgets applications.

However when I add the line

#include <boost/property_tree/ptree.hpp>

to a simple wxWidgets I suddenly get compilation errors:

||=== Build: Release in pulley_client_gui (compiler: GNU GCC Compiler) ===|
C:\Users\James\code\wxWidgets-3.0.1\include\wx\msw\winundef.h||In function 'HWND__* CreateDialog(HINSTANCE, LPCTSTR, HWND, DLGPROC)':|
C:\Users\James\code\wxWidgets-3.0.1\include\wx\msw\winundef.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:\Users\James\code\wxWidgets-3.0.1\include\wx\msw\winundef.h||In function 'HFONT__* CreateFont(int, int, int, int, int, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, LPCTSTR)':|
C:\Users\James\code\wxWidgets-3.0.1\include\wx\msw\winundef.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:\Users\James\code\wxWidgets-3.0.1\include\wx\msw\winundef.h||In function 'HWND__* CreateWindow(LPCTSTR, LPCTSTR, DWORD, int, int, int, int, HWND, HMENU, HINSTANCE, LPVOID)':|
C:\Users\James\code\wxWidgets-3.0.1\include\wx\msw\winundef.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:\Users\James\code\wxWidgets-3.0.1\include\wx\msw\winundef.h||In function 'HMENU__* LoadMenu(HINSTANCE, LPCTSTR)':|
C:\Users\James\code\wxWidgets-3.0.1\include\wx\msw\winundef.h|111|error: cannot convert 'LPCTSTR {aka const char*}' to 'LPCWSTR {aka const wchar_t*}' for argument '2' to 'HMENU__* LoadMenuW(HINSTANCE, LPCWSTR)'|
C:\Users\James\code\wxWidgets-3.0.1\include\wx\msw\winundef.h||In function 'HICON__* LoadIcon(HINSTANCE, LPCTSTR)':|
C:\Users\James\code\wxWidgets-3.0.1\include\wx\msw\winundef.h|311|error: cannot convert 'LPCTSTR {aka const char*}' to 'LPCWSTR {aka const wchar_t*}' for argument '2' to 'HICON__* LoadIconW(HINSTANCE, LPCWSTR)'|
C:\Users\James\code\wxWidgets-3.0.1\include\wx\msw\winundef.h||In function 'HBITMAP__* LoadBitmap(HINSTANCE, LPCTSTR)':|
C:\Users\James\code\wxWidgets-3.0.1\include\wx\msw\winundef.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)) ===|

This would seem to indicate that the wxWidgets methods can no longer handle UTF8 parameters, the ability to convert to UTF16 has been broken by the boost header file.

Found a workaround. If I include the boost header AFTER the wxWidgets headers then compilation is successful.

It seems that UNICODE definition is inconsistent, ie it's defined (or not) when <windows.h> is included from Boost headers and not defined (or is) when wxWidgets headers are included.

To prevent this from ever happening, the recommended solution is to define UNICODE in your make or project file, so that it is defined on the command line. Chances are you already define _UNICODE there (if using MSVS projects), but this only affects the CRT headers and you need UNICODE as well for <windows.h> .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM