0

I compiled wxWidgets 3.0.3 on Windows using MinGW64 7.2

mingw32-make -j4 -f makefile.gcc BUILD=debug SHARED=0 UNICODE=1

I then created a sample project "Hello world" with CLion 2017.3, and compiled using CMake.

cmake_minimum_required(VERSION 3.9)
project(wx_widgets_hello_world)

set(CMAKE_CXX_STANDARD 11)

set(wxWidgets_ROOT_DIR "C:/wx_widgets_3_0_3")
set(wxWidgets_CONFIGURATION mswud)
find_package(wxWidgets COMPONENTS adv core base REQUIRED)
include(${wxWidgets_USE_FILE})

add_executable(wx_widgets_hello_world main.cpp)
target_link_libraries(wx_widgets_hello_world ${wxWidgets_LIBRARIES})

Included headers are

#include <wx/wx.h>
#include <wx/grid.h>

adv is there because I'm experimenting the wxGrid class. I check the produced .exe and it is 90MB. Sure I'm doing something wrong. Any thought?

I'm not an expert with CMake (never used before), but maybe its because I'm linking all the libraries (adv base core) with

target_link_libraries(wx_widgets_hello_world ${wxWidgets_LIBRARIES})
Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
LppEdd
  • 20,274
  • 11
  • 84
  • 139
  • 1
    And what is total size of "adv", "core", and "base" libraries in your wxWidgets installation? As you build them statically, they become the part of your executable. – Tsyvarev Dec 24 '17 at 20:54
  • @MarkSetchell I meant megabytes. – LppEdd Dec 24 '17 at 22:01

1 Answers1

0

Firstly, Debug builds are always way larger than Release ones, since they contain a lot of information used for debugging. So, checking a Release build size would give you much more useful information.

Secondly, I assume that SHARED=0 means that wxWidgets is build as a static library, and is linked statically. What it means is that the whole library is merged into your executable. It is generally better to actually use shared versions of libraries, for a variety of reasons. In particular, this will dramatically reduce the executable size. Note that the user will need the wxWidgets shared library anyway to run your executable, but it may be already installed on his system.

Finally, have a look at object stripping. It is a process that removes unused symbols (functions, global variables, etc) from your executable. I don't know whether CMake does this by default. The GCC compiler option "-Os" (optimize for size) is also a nice thing to do for release builds.

lisyarus
  • 15,025
  • 3
  • 43
  • 68
  • Sure debug contains more info and therefore results in a bigger size, but damn, 90Mb? No way. Seems I'm linking all of wxWidgets – LppEdd Dec 24 '17 at 20:45
  • @LppEdd For a really large project in release build even with all dependencies being shared a 90 Mb size is quite expectable. In your case the project seems small, so, yes, statically linked wxWidgets should be the main case. – lisyarus Dec 24 '17 at 20:54
  • 2
    Turned out I had to use the -strip compiler flag. Still with MinGW (GCC) a basic wxFrame results in a 5Mb~ binary. – LppEdd Dec 27 '17 at 11:17