使用Mingw64编译wxWidgets3.0.2,首先得下载wxMSW-Setup-3.0.2.exe(https://sourceforge.net/projects/wxwindows/files/3.0.2/wxMSW-Setup-3.0.2.exe,然后按照如下步骤编译(假设要编译一个Unicode共享库版的wxWidgets):
cd X:/wxWidgets-3.0.2/build/msw
make -f makefile.gcc SHARED=1 UNICODE=1
然而编译到一半,从C代码变为C++代码时,就会产生如下错误(有许多类似错误,只选取一处):
In file included from e:/mingwd/mingw/include/c++/5.2.0/type_traits:35:0,
from ../../include/wx/strvararg.h:25,
from ../../include/wx/string.h:46,
from ../../include/wx/any.h:19,
from ../../src/common/any.cpp:18:
e:/mingwd/mingw/include/c++/5.2.0/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
既然只是c++11支持没有打开的问题,只要改一下CXXFLAGS即可,于是乎,按如下命令重新编译。
make -f makefile.gcc CXXFLAGS="-std=c++11" SHARED=1 UNICODE=1 clean
make -f makefile.gcc CXXFLAGS="-std=c++11" SHARED=1 UNICODE=1
这次编译完了所有中间件,但是到链接时候又出了问题:
E:/wxWidgets-3.0.2/lib/gcc_lib64/libwxmsw30ud.a(monolib_filename.o): In function `wxChmod(wxString const&, unsigned short)':
E:/wxWidgets-3.0.2/build/msw/../../include/wx/filefn.h:513: undefined reference to `wxMSLU__wchmod(wchar_t const*, int)'
E:/wxWidgets-3.0.2/lib/gcc_lib64/libwxmsw30ud.a(monolib_filename.o): In function `wxOpen(wxString const&, int, unsigned short)':
E:/wxWidgets-3.0.2/build/msw/../../include/wx/filefn.h:515: undefined reference to `wxMSLU__wopen(wchar_t const*, int, int)'
E:/wxWidgets-3.0.2/lib/gcc_lib64/libwxmsw30ud.a(monolib_file.o): In function `wxRemove(wxString const&)':
E:/wxWidgets-3.0.2/build/msw/../../include/wx/wxcrt.h:758: undefined reference to `wxMSLU__wremove(wchar_t const*)'
E:/wxWidgets-3.0.2/lib/gcc_lib64/libwxmsw30ud.a(monolib_file.o): In function `wxAccess(wxString const&, unsigned short)':
......
这实在是令我百思不得其解了,翻遍了docs文件夹的每个角落,终于在install.txt中找到了答案,里面有这么一句话:
C++11 note: If you want to compile wxWidgets in C++11 mode, you currently have
to use -std=gnu++11 switch as -std=c++11 disables some extensions
that wxWidgets relies on. I.e. please use CXXFLAGS="-std=gnu++11".
说的很清楚,不能用”std=c++11"进行编译,这会导致一些wxWidgets依赖的extensions(扩展名?)被屏蔽的问题。然后用以下命令重新编译,就成功了。
make -f makefile.gcc CXXFLAGS="-std=gnu++11" SHARED=1 UNICODE=1 clean
make -f makefile.gcc CXXFLAGS="-std=gnu++11" SHARED=1 UNICODE=1
上面说到关于extensions,这里的意思应该是扩展,即gnu的g++(gcc)提供给c/c++代码除c++标准以外的支持。如果这些支持没有被启用,自然会导致上面像wxWidgets的库编译失败,不过这么依赖语言外的额外实现也不见得是件好事吧。
新闻热点
疑难解答
图片精选