original source: http://wiki.wxwidgets.org/Compiling_wxWidgets_with_MinGW
InstallMinGW
Please follow the steps described in InstallingMinGW under Windows.
Download and Install wxWidgets
See Downloadingand installing wxWidgets.
Build the library
Open the command prompt (Start > Run...> cmd). Change the directory to thebuild\msw folder. For example:
CD wx\wx288\build\msw
Clean up the source:
mingw32-make -f makefile.gcc SHARED=1 UNICODE=1 BUILD=release clean
Then, compile the library:
mingw32-make -f makefile.gcc SHARED=1 UNICODE=1 BUILD=release
You can add the -j parameter to use parallel builds, e.g. -j4 touse 4 cores
Note: For more information on the UNICODE andBUILD options, see WxWidgetsBuild Configurations. |
Build Output
In the example above a DLL was created under\lib\gcc_dll. The resultant setup.h file can befound under \lib\gcc_dll\mswu\wx
Executables created with can be rather BIG. In case you compilein DEBUG mode, the files become VERY BIG (>20 MBwxWidgets Minimal sample). With strip you can reduce thesize, but it will always remain bigger than executables createdwith Visual Studio. In addition to that, Visual Studio seems tocompile faster but I am not sure about this.
Troubleshooting
Build the static library
If you cannot build wxWidgets static library, try the followingcommands (specify SHELL=CMD.exe, otherwise mingw32-make (GNU make)will use sh.exe as SHELL by default):
a. Build UNICODE version, static library:
mingw32-make SHELL=CMD.exe -j4 -f makefile.gcc BUILD=release UNICODE=1 SHARED=0
b. Build UNICODE version, MONOLITHIC static library:
mingw32-make SHELL=CMD.exe -j4 -f makefile.gcc BUILD=release UNICODE=1 SHARED=0 MONOLITHIC=1
Specify -j4 option to build wxWidgets library using 4 paralleljobs (if your CPU has 4 threads/cores). It will increase yourbuilding speed by ~4 times.
CreateProcess, The system cannot find the filespecified.
if you get errors like this:
if not exist gcc_mswu mkdir gcc_mswu
process_begin: CreateProcess(NULL, -c "if not exist gcc_mswu mkdir gcc_mswu", ...) failed.
make (e=2): The system cannot find the file specified.
mingw32-make: [gcc_mswu] Error 2 (ignored)
if not exist ....libgcc_lib mkdir ....libgcc_lib
process_begin: CreateProcess(NULL, -c "if not exist ....libgcc_lib mkdir ....libgcc_lib", ...) failed.
make (e=2): The system cannot find the file specified.
mingw32-make: *** [....libgcc_lib] Error 2
it's probably because you have MSYS (or CYGWIN) installed andthe MSYS\bin folder in your PATH, and this confuses mingw32-make.Remove the MSYS\bin folder from your PATH and try again, it shouldwork. (Alternatively, use MSYS to build wxWidgets, as described inbuild\msw\install.txt in the wxWidgets source tree).
Note: MSYS\bin turns in to /bin, if you look from MinGWshell.
If you don`t have MSYS, edit your PATh=H environment variableand make sure your PATH points to the bin directory of your mingwinstallation.
Alternative: mingw32-make -f makefile.gcc SHELL=CMD .... (butgive me command line too long at linking.)
To fix the issue "The input line is too long" whencompile static library with MONOLITHIC option
Please modify makefile.gcc as following:
From:
ifeq ($(MONOLITHIC),1)
ifeq ($(SHARED),0)
$(LIBDIRNAME)libwx$(PORTNAME)$(WXUNIVNAME)$(WX_RELEASE_NODOT)$(WXUNICODEFLAG)$(WXDEBUGFLAG)$(WX_LIB_FLAVOUR).a: $(MONOLIB_OBJECTS)
if exist $@ del $@
ar rcu $@ $(MONOLIB_OBJECTS)
ranlib $@
endif
endif
Replace $(MONOLIB_OBJECTS) withgcc_mswu\monolib*.o:
ifeq ($(MONOLITHIC),1)
ifeq ($(SHARED),0)
$(LIBDIRNAME)libwx$(PORTNAME)$(WXUNIVNAME)$(WX_RELEASE_NODOT)$(WXUNICODEFLAG)$(WXDEBUGFLAG)$(WX_LIB_FLAVOUR).a: $(MONOLIB_OBJECTS)
if exist $@ del $@
ar rcu $@ gcc_mswu\monolib*.o
ranlib $@
endif
endif
Memory Exhausted (bin/ld.exe: out of memory allocating Nbytes)
If you get "memory exhausted" errors, this is due to a Mingwbug.
tdm-mingw tends to be less prone to thisissue
Note: Make sure to make a clean build after switchingcompilers. Also if you install both regular and TDM mingw checkyour PATH carefully to get the correct one when you build. |
It is also recommended to build non-monolithic, since monolithicbuilds take more RAM (debug builds especially; some people reportthat monolithic-debug builds require more RAM than a 32-bits systemcan have).
Another option is to add the following buildflags CXXFLAGS="-fno-keep-inline-dllexport"
References:
- http://forums.wxwidgets.org/viewtopic.php?f=19&t=30393&p=130532
- http://forums.wxwidgets.org/viewtopic.php?f=19&t=29946&p=129658
ld returned 5 exit status
You most likely got this after experiencing the error above andswitching to TDM gcc and trying the build again. This seems to berelated to the leftover remnants from your previous build.(mingw32-make -f makefile.gcc
seems insufficient toclean this).
Try building from a fresh wxWidgets source tree
undefined reference
While compiling your projects, you might get some "undefinedreference" errors. In my case this was due to a wrong order in theg++ call
This might not work (please note the respective positions of"-lwx_mswXXXXXX" and"XXXXXXXXXXX/libXXXXXX.a")
g++ -Wall -g -fexceptions -Wall -g -fexceptions -I/usr/local/lib/wx/include/msw-ansi-release-2.6 \ -I/usr/local/include/wx-2.6 -D__WXMSW__ -DWXUSINGDLL=1 -DNO_GCC_PRAGMA -o xpe.exe -Wl,--subsystem \ -Wl,windows -mwindows xpe.o xpemw.o -L/usr/local/lib -mthreads -lwx_msw_xrc-2.6 -lwx_msw_qa-2.6 \ -lwx_msw_html-2.6 -lwx_msw_adv-2.6 -lwx_msw_core-2.6 -lwx_base_xml-2.6 -lwx_base_net-2.6 \ -lwx_base-2.6 ../src/components/codeeditor/libcodeeditor.a ../src/lib/liblogging.a ../src/lib/libstring.a ../src/components/codeeditor/libcodeeditor.a(tcodeeditor.o)(.text+0x169): In function `ZN11TCodeEditorC2EP8wxWindowiRK8wxString': C:/GNU/msys/1.0/home/Administrateur/xpe_project/src/components/codeeditor/tcodeeditor.cpp:45: undefined reference to `_imp__wxDefaultSize' ../src/components/codeeditor/libcodeeditor.a(tcodeeditor.o)(.text+0x2f4): C:/GNU/msys/1.0/home/Administrateur/xpe_project/src/components/codeeditor/tcodeeditor.c pp:46: undefined reference to `_imp___ZN22wxSystemSettingsNati ve9GetColourE14wxS
This correction should make it working (please note therespective positions of "-lwx_mswXXXXXX" and"XXXXXXXXXXX/libXXXXXX.a"):
g++ -Wall -g -fexceptions -Wall -g -fexceptions -I/usr/local/lib/wx/include/msw-ansi-release-2.6 \ -I/usr/local/include/wx-2.6 -D__WXMSW__ -DWXUSINGDLL=1 -DNO_GCC_PRAGMA -o xpe.exe -Wl,--subsystem \ -Wl,windows -mwindows xpe.o xpemw.o ../src/components/codeeditor/libcodeeditor.a ../src/lib/liblogging.a \ ../src/lib/libstring.a -L/usr/local/lib -mthreads -lwx_msw_xrc-2.6 -lwx_msw_qa-2.6 -lwx_msw_html-2.6 \ -lwx_msw_adv-2.6 -lwx_msw_core-2.6 -lwx_base_xml-2.6 -lwx_base_net-2.6 -lwx_base-2.6
Winavr interference
In some cases, actually everything is fine, but you might havemore than one similar complier installed on your machine.
For a real example, I haveC:\WinAVR-20100110\bin;C:\WinAVR-20100110\utils\bin; installed onmy machine for some microcontroller firmware development.
The installed WinAVR containing a series GNU compiler like gcc,g++ , etc.
As the WinAVR tool chain is also registered to the window viaPATH environment variable.So same kind of error as aboved occurswhen I tried to compile wxWidgets-2.8.11.
This could be solved by temporary remove the related Winavrdirectory locaiton from PATH environment variable.(Not only yourcurrent user environment variable also the Global environmentvariable set by administrator)