Mingw64編譯wxWidgets 3.0.2常見錯(cuò)誤分析
使用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,然后按照如下步驟編譯(假設(shè)要編譯一個(gè)Unicode共享庫版的wxWidgets):
cd X:\wxWidgets-3.0.2\build\msw
make -f makefile.gcc SHARED=1 UNICODE=1
然而編譯到一半,從C代碼變?yōu)镃++代碼時(shí),就會(huì)產(chǎn)生如下錯(cuò)誤(有許多類似錯(cuò)誤,只選取一處):
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
這次編譯完了所有中間件,但是到鏈接時(shí)候又出了問題:
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)':
......
這實(shí)在是令我百思不得其解了,翻遍了docs文件夾的每個(gè)角落,終于在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"進(jìn)行編譯,這會(huì)導(dǎo)致一些wxWidgets依賴的extensions(擴(kuò)展名?)被屏蔽的問題。然后用以下命令重新編譯,就成功了。
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
后記
上面說到關(guān)于extensions,這里的意思應(yīng)該是擴(kuò)展,即gnu的g++(gcc)提供給c/c++代碼除c++標(biāo)準(zhǔn)以外的支持。如果這些支持沒有被啟用,自然會(huì)導(dǎo)致上面像wxWidgets的庫編譯失敗,不過這么依賴語言外的額外實(shí)現(xiàn)也不見得是件好事吧。
相關(guān)文章
C++知識(shí)點(diǎn)之成員函數(shù)中const的用法
這篇文章主要介紹了C++知識(shí)點(diǎn)之成員函數(shù)中const的用法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-11-11
概述C++中的 public protected private friend關(guān)鍵字的用法
這篇文章簡要概述了C++中的 public protected private friend關(guān)鍵字的用法,非常不錯(cuò),具有參考借鑒價(jià)值,感興趣的朋友一起學(xué)習(xí)吧2016-08-08
C++實(shí)現(xiàn)航空訂票系統(tǒng)課程設(shè)計(jì)
這篇文章主要為大家詳細(xì)介紹了C++實(shí)現(xiàn)航空訂票系統(tǒng)課程設(shè)計(jì),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-03-03
C++類模板實(shí)戰(zhàn)之vector容器的實(shí)現(xiàn)
本文我們將做一個(gè)類模板實(shí)戰(zhàn)-手寫精簡版vector容器。讓我們自己封裝一個(gè)數(shù)組類,可以適應(yīng)基本數(shù)據(jù)類型和自定義數(shù)據(jù)類型,感興趣的可以了解一下2022-07-07

