其实利用MinGW编译wxWidgets是一件挺简单的事情,但是最近在编译的时候遇到一些问题,并找到解决方案,因此在此分享一下个人经验。编译出错的原因是由于安装了MSYS的缘故。
错误信息类似于如下的结果:
if not exist ../../lib/gcc_lib/mswud/wx mkdir ../../lib/gcc_lib/mswud/wx
process_begin: CreateProcess(NULL, -c "if not exist ../../lib/gcc_lib/mswud/wx mkdir ../../lib/gcc_lib/mswud/wx", ...) failed.
make (e=2)
产生错误的原因是因为安装了MSYS后,利用Make命令会首先执行MSYS中的SHELL命令,从而会导致编译错误,对于这种情况,可以修改 $(WX)/build/msw目录中的makefile.gcc文件,使其默认采用CMD命令行。
makefile.gcc修改前: SHELL := $(COMSPEC)
makefile.gcc修改后: C:\WINDOWS\system32\CMD.exe (该路径为实际的CMD.exe的路径)
==============================================================================
最后还是顺便说一下MinGW编译wxWidgets的流程:
1 下载源代码 http://www.wxwidgets.org/downloads/
2 修改 $(WX)/build/msw 目录中的makefile.gcc文件 (可选)
3 修改 $(WX)/build/msw 目录中的congfig.gcc文件 ()
4 在控制台进入到 $(WX)/build/msw 目录中,执行 mingw32-make -f makefile.gcc
注: $(WX)表示你下载的源代码解压后的路径
对编译过程还不明白的可以查看官方说明:
http://wiki.wxwidgets.org/Compiling_wxWidgets_with_MinGW
==============================================================================
congfig.gcc文件
1# ========================================================================= 2# This configuration file was generated by 3# Bakefile 0.2.9 (http://www.bakefile.org) 4# Beware that all changes made to this file will be overwritten next 5# time you run Bakefile! 6# ========================================================================= 7 8 9# ------------------------------------------------------------------------- 10# These are configurable options: 11# ------------------------------------------------------------------------- 12 13# Compiler flags to link shared library 14LINK_DLL_FLAGS ?= -shared 15 16# Compiler flags to link loadable module 17LINK_MODULE_FLAGS ?= -shared 18 19# C compiler 20CC = gcc 21 22# C++ compiler 23CXX = g++ 24 25# Standard flags for CC 26CFLAGS ?= 27 28# Standard flags for C++ 29CXXFLAGS ?= 30 31# Standard preprocessor flags (common for CC and CXX) 32CPPFLAGS ?= 33 34# Standard linker flags 35LDFLAGS ?= 36 37# The C preprocessor 38CPP ?= $(CC) -E 39 40# What type of library to build? [0,1] 41SHARED ?= 1 42 43# Build wxUniversal instead of native port? [0,1] 44WXUNIV ?= 0 45 46# Compile Unicode build of wxWidgets? [0,1] 47UNICODE ?= 1 48 49# Use MSLU library when building Unicode version. [0,1] 50MSLU ?= 0 51 52# Type of compiled binaries [debug,release] 53BUILD ?= release 54 55# Should debugging info be included in the executables? The default value 56# "default" means that debug info will be included if BUILD=debug 57# and not included if BUILD=release. [0,1,default] 58DEBUG_INFO ?= default 59 60# Should __WXDEBUG__ be defined? The default value "default" means that it will 61# be defined if BUILD=debug and not defined if BUILD=release. [0,1,default] 62DEBUG_FLAG ?= default 63 64# Multiple libraries or single huge monolithic one? [0,1] 65MONOLITHIC ?= 1 66 67# Build GUI libraries? [0,1] 68USE_GUI ?= 1 69 70# Build wxHTML library (USE_GUI must be 1)? [0,1] 71USE_HTML ?= 1 72 73# Build multimedia library (USE_GUI must be 1)? [0,1] 74USE_MEDIA ?= 1 75 76# Build wxXRC library (USE_GUI must be 1)? [0,1] 77USE_XRC ?= 1 78 79# Build wxAUI library (USE_GUI must be 1)? [0,1] 80USE_AUI ?= 1 81 82# Build wxRichTextCtrl library (USE_GUI must be 1)? [0,1] 83USE_RICHTEXT ?= 1 84 85# Build OpenGL canvas library (USE_GUI must be 1)? [0,1] 86USE_OPENGL ?= 0 87 88# Build ODBC database classes (USE_GUI must be 1)? [0,1] 89USE_ODBC ?= 0 90 91# Build quality assurance classes library (USE_GUI must be 1)? [0,1] 92USE_QA ?= 0 93 94# Enable exceptions in compiled code. [0,1] 95USE_EXCEPTIONS ?= 1 96 97# Enable run-time type information (RTTI) in compiled code. [0,1] 98USE_RTTI ?= 1 99 100# Enable threading in compiled code. [0,1] 101USE_THREADS ?= 1 102 103# Enable wxCairoContext for platforms other than Linux/GTK. [0,1] 104USE_CAIRO ?= 0 105 106# Link with gdiplus.lib? (Needed for wxGraphicsContext, will also set wxUSE_GRAPHICS_CONTEXT) [0,1] 107USE_GDIPLUS ?= 0 108 109# Is this official build by wxWidgets developers? [0,1] 110OFFICIAL_BUILD ?= 0 111 112# Use this to name your customized DLLs differently 113VENDOR ?= custom 114 115# 116WX_FLAVOUR ?= 117 118# 119WX_LIB_FLAVOUR ?= 120 121# Name of your custom configuration. This affects directory 122# where object files are stored as well as the location of 123# compiled .lib files and setup.h under the lib/ toplevel directory. 124CFG ?= 125 126# Compiler flags needed to compile test suite in tests directory. If you want 127# to run the tests, set it so that the compiler can find CppUnit headers. 128CPPUNIT_CFLAGS ?= 129 130# Linker flags needed to link test suite in tests directory. If you want 131# to run the tests, include CppUnit library here. 132CPPUNIT_LIBS ?= 133 134# Version of C runtime library to use. You can change this to 135# static if SHARED=0, but it is highly recommended to not do 136# it if SHARED=1 unless you know what you are doing. [dynamic,static] 137RUNTIME_LIBS ?= dynamic 138 139# Set the version of your Mingw installation here. 140# "3" ...... this is for Mingw 2.0 or newer (comes with gcc3) 141# "2.95" ... for Mingw 1.1 or any of the older versions [3,2.95] 142GCC_VERSION ?= 3