安装wxWidgets
从官网可下载源码安装包。安装后,建立批处理文件对其进行编译:
gvim bwx.bat
内容如下:
@echo off
set WXWIN=C:\wxWidgets-3.0.2
pushd %WXWIN%\build\msw
mingw32-make -f makefile.gcc BUILD=release SHARED=0 UNICODE=1 WXUNIV=0 MONOLITHIC=0 USE_GUI=1 RUNTIME_LIBS=static MSLU=1 DEBUG_FLAG=0 DEBUG_INFO=0 CXXFLAGS="-std=gnu++11" CPPFLAGS="-w" -j8 clean
mingw32-make -f makefile.gcc BUILD=release SHARED=0 UNICODE=1 WXUNIV=0 MONOLITHIC=0 USE_GUI=1 RUNTIME_LIBS=static MSLU=1 DEBUG_FLAG=0 DEBUG_INFO=0 CXXFLAGS="-std=gnu++11" CPPFLAGS="-w -m32" LDFLAGS="-m32" CFG=32 -j8 clean
mingw32-make -f makefile.gcc BUILD=release SHARED=0 UNICODE=1 WXUNIV=0 MONOLITHIC=0 USE_GUI=1 RUNTIME_LIBS=static MSLU=1 DEBUG_FLAG=0 DEBUG_INFO=0 CXXFLAGS="-std=gnu++11" CPPFLAGS="-w" -j8
mingw32-make -f makefile.gcc BUILD=release SHARED=0 UNICODE=1 WXUNIV=0 MONOLITHIC=0 USE_GUI=1 RUNTIME_LIBS=static MSLU=1 DEBUG_FLAG=0 DEBUG_INFO=0 CXXFLAGS="-std=gnu++11" CPPFLAGS="-w -m32" LDFLAGS="-m32" CFG=32 -j8
popd
执行bwx.bat即可完成编译。然后建立新的批处理文件:
gvim gwx.bat
内容如下:
@ECHO OFF
SET WXWIN=C:\wxWidgets-3.0.2
SET WXCFG=gcc_lib\mswu
FOR /F "delims=" %%i IN ('wx-config --libs') DO SET WXLIBS=%%i
g++ %1 -o %~n1 -s -Os -I%WXWIN%\include -I%WXWIN%\lib\gcc_lib\mswu -Wno-deprecated-declarations -std=gnu++11 %WXLIBS% -mwindows
SET WXCFG=gcc_lib32\mswu
FOR /F "delims=" %%i IN ('wx-config --libs') DO SET WXLIBS=%%i
g++ %1 -o %~n1_32 -s -Os -I%WXWIN%\include -I%WXWIN%\lib\gcc_lib32\mswu -Wno-deprecated-declarations -std=gnu++11 %WXLIBS% -mwindows
即可编译调用了wxWidgets库的C++程序。可新建文件:
gvim hello.cpp
内容如下:
#define wxDEBUG_LEVEL 0
#include <wx/wx.h>
class MyApp : public wxApp
{
public:
virtual bool OnInit()
{
wxMessageBox(wxT("Hello, world!"));
return false;
}
};
IMPLEMENT_APP(MyApp)
执行:
gwx hello.cpp && hello
可进行测试。