有关减少wxWidgets应用程序代码大小的任何提示? [英] Any tips on reducing wxWidgets application code size?

查看:175
本文介绍了有关减少wxWidgets应用程序代码大小的任何提示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个最小的wxWidgets应用程序:

I have written a minimal wxWidgets application:

stdafx.h

#define wxNO_REGEX_LIB
#define wxNO_XML_LIB
#define wxNO_NET_LIB
#define wxNO_EXPAT_LIB
#define wxNO_JPEG_LIB
#define wxNO_PNG_LIB
#define wxNO_TIFF_LIB
#define wxNO_ZLIB_LIB
#define wxNO_ADV_LIB
#define wxNO_HTML_LIB
#define wxNO_GL_LIB
#define wxNO_QA_LIB
#define wxNO_XRC_LIB
#define wxNO_AUI_LIB
#define wxNO_PROPGRID_LIB
#define wxNO_RIBBON_LIB
#define wxNO_RICHTEXT_LIB
#define wxNO_MEDIA_LIB
#define wxNO_STC_LIB

#include <wx/wxprec.h>

Minimal.cpp

Minimal.cpp

#include "stdafx.h"
#include <memory>
#include <wx/wx.h>

class Minimal : public wxApp
{
public:
    virtual bool OnInit();
};

IMPLEMENT_APP(Minimal)
DECLARE_APP(Minimal)

class MinimalFrame : public wxFrame
{
    DECLARE_EVENT_TABLE()
public:
    MinimalFrame(const wxString& title);
    void OnQuit(wxCommandEvent& e);
    void OnAbout(wxCommandEvent& e);
};

BEGIN_EVENT_TABLE(MinimalFrame, wxFrame)
    EVT_MENU(wxID_ABOUT, MinimalFrame::OnAbout)
    EVT_MENU(wxID_EXIT, MinimalFrame::OnQuit)
END_EVENT_TABLE()

MinimalFrame::MinimalFrame(const wxString& title)
    : wxFrame(0, wxID_ANY, title)
{
    std::auto_ptr<wxMenu> fileMenu(new wxMenu);
    fileMenu->Append(wxID_EXIT, L"E&xit\tAlt-X", 
        L"Terminate the Minimal Example.");
    std::auto_ptr<wxMenu> helpMenu(new wxMenu);
    helpMenu->Append(wxID_ABOUT, L"&About\tF1",
        L"Show the about dialog box.");

    std::auto_ptr<wxMenuBar> bar(new wxMenuBar);
    bar->Append(fileMenu.get(), L"&File");
    fileMenu.release();
    bar->Append(helpMenu.get(), L"&Help");
    helpMenu.release();

    SetMenuBar(bar.get());
    bar.release();

    CreateStatusBar(2);
    SetStatusText(L"Welcome to wxWidgets!");
}

void MinimalFrame::OnAbout(wxCommandEvent& e)
{
    wxMessageBox(L"Some text about me!", L"About", wxOK, this);
}

void MinimalFrame::OnQuit(wxCommandEvent& e)
{
    Close();
}

bool Minimal::OnInit()
{
    std::auto_ptr<MinimalFrame> mainFrame(
        new MinimalFrame(L"Minimal wxWidgets Application"));
    mainFrame->Show();
    mainFrame.release();
    return true;
}

这个最小程序重2.4MB! (可执行压缩把这减少到一半MB左右,但是仍然巨大!)(我必须静态链接,因为这个应用程序需要单二进制xcopy部署,所以C运行时和wxWidgets本身设置为静态链接)

This minimal program weighs in at 2.4MB! (Executable compression drops this to half a MB or so but that's still HUGE!) (I must statically link because this application needs to be single-binary-xcopy-deployed, so both the C runtime and wxWidgets itself are set for static linking)

有关减少此问题的任何提示? (我使用Microsoft Visual Studio 2010)

Any tips on cutting this down? (I'm using Microsoft Visual Studio 2010)

推荐答案

你可以另外设置MSVC编译为小二进制大小冲击性能当然)通过使用标志 / 01 。请参见此处。还要记住,wxWidgets需要被编译为这样有这个影响。

You can additionally set MSVC to compile for small binary size (but this might impact performance of course) by using the flag /01. See here. Also remember that wxWidgets will need to be compiled as such for this to have any impact.

我认为2.4 MB的静态链接的应用程序是相当不错的IMHO .. 。

And I think that 2.4 MB for a statically linked app is pretty decent IMHO...

UPDATE wxWidgets wiki可执行文件大小可能带来一些安慰...

UPDATE: the wxWidgets wiki on executable size might bring some comfort...

这篇关于有关减少wxWidgets应用程序代码大小的任何提示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆