如何使用wxWidgets构建独立的exe文件?我正在使用C ++和CodeBlocks:
答案 0 :(得分:2)
以下是为code :: blocks
构建wxWidgets库所需的说明http://wiki.codeblocks.org/index.php?title=Compiling_wxWidgets_3.0.0_to_develop_Code::Blocks_(MSW)
构建一个静态库以与程序链接
mingw32-make -f makefile.gcc USE_XRC=1 SHARED=0 MONOLITHIC=1 BUILD=release UNICODE=1
结果应与此类似:
Directory of J:\wxWidgets-src-3.0.1\lib\gcc_lib
09/10/2014 12:45 PM <DIR> .
09/10/2014 12:45 PM <DIR> ..
09/10/2014 12:45 PM 202,752 libwxexpat.a
09/10/2014 12:45 PM 151,230 libwxjpeg.a
09/10/2014 12:45 PM 48,398,492 libwxmsw30u.a
09/10/2014 12:45 PM 223,374 libwxmsw30u_gl.a
09/10/2014 12:44 PM 227,850 libwxpng.a
09/10/2014 12:44 PM 81,428 libwxregexu.a
09/10/2014 12:45 PM 2,830,642 libwxscintilla.a
09/10/2014 12:45 PM 454,846 libwxtiff.a
09/10/2014 12:44 PM 86,432 libwxzli
以下是最小wxWidgets GUI应用程序的源代码
#include <wx/wx.h>
#include <wx/app.h>
class cApp : public wxApp
{
public:
virtual bool OnInit();
};
class cFrame: public wxFrame
{
public:
cFrame(wxFrame *frame, const wxString& title)
: wxFrame(frame, -1, title, wxPoint(-1,-1),wxSize(600,600))
{
}
};
IMPLEMENT_APP(cApp);
bool cApp::OnInit()
{
cFrame* frame = new cFrame(0L, _("wx Starter"));
frame->Show();
return true;
}
将此保存为starter.cpp
这是构建此应用程序的code :: blocks项目。有三个目标:Debug和Release使用共享库(DLL)和Static,它是使用静态库的发布版本(全部在一个可执行文件中)。
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
<FileVersion major="1" minor="6" />
<Project>
<Option title="starter" />
<Option pch_mode="2" />
<Option compiler="gcc" />
<Build>
<Target title="Debug">
<Option output="bin/starter" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Debug/" />
<Option type="0" />
<Option compiler="gcc" />
<Compiler>
<Add option="-std=c++11" />
<Add option="-g" />
</Compiler>
<Linker>
<Add library="wxbase30u" />
<Add library="wxmsw30u_core" />
<Add directory="$(#wxwidgets.lib)" />
</Linker>
</Target>
<Target title="Release">
<Option output="bin/starter" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Release/" />
<Option type="0" />
<Option compiler="gcc" />
<Compiler>
<Add option="-O2" />
</Compiler>
<Linker>
<Add option="-s" />
<Add library="wxbase30u" />
<Add library="wxmsw30u_core" />
<Add directory="$(#wxwidgets.lib)" />
</Linker>
</Target>
<Target title="Static">
<Option output="bin/starter_static" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Release/" />
<Option type="0" />
<Option compiler="gcc" />
<Compiler>
<Add option="-O2" />
</Compiler>
<Linker>
<Add option="-s" />
<Add library="wxmsw30u" />
<Add library="wxpng" />
<Add library="wxzlib" />
<Add library="ole32" />
<Add library="Comctl32" />
<Add library="uuid" />
<Add library="OleAut32" />
<Add library="Winspool" />
<Add directory="$(#wxwidgets_static.lib)" />
</Linker>
</Target>
</Build>
<Compiler>
<Add option="-std=c++11" />
<Add directory="$(#wxwidgets.include)" />
<Add directory="$(#wxwidgets.setup)" />
</Compiler>
<Unit filename="starter.cpp" />
<Extensions>
<code_completion />
<envvars />
<debugger />
</Extensions>
</Project>
</CodeBlocks_project_file>
将此保存为starter.cbp在同一文件夹中。当您打开它时,系统将提示您设置指向构建库的文件夹所需的全局变量。这样做一次,它将适用于您的所有项目。