[转]Compiling wxWidgets

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

NOTE:

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 : http://tdm-gcc.tdragon.net/ Thisapplies to MinGW with installers 20110316 and 20110530 atleast.

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:

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 : your static libs MUST be given beforeshared libs.

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___ZN22wxSystemSettingsNative9GetColourE14wxS

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)

个人研究成果,wxWidgets的外围通讯库基本一直处于空缺状态,经过几天的研究,将我个人的研究成果上传共享。 本库基于官方于2011年最后一次更新的libctb-0.16版本为基础修改而来,工程使用CodeBlocks创建,相较原版的变更如下。 1.去掉了ctb命名空间,之前用起来感觉有点别扭,所以去掉了,不过为了兼容性考虑,以后可能加回来。 2.IOBase、SerialPort(继承自IOBase)、GPIB(继承自IOBase)三个类修改了构造函数,原来FIFO缓冲的尺寸固定为256,我觉得波特率高时候可能不够用,现在改为通过构造函数传参由用户指定,示例程序中使用4096。 3.修正一个严重的BUG,在SerialPort基类中的OpenDedvice方法中,当串口附加参数为NULL时,类内的附加参数结构体成员将在没有被始化就被使用,进而因参数混乱而导致收发异常,这个BUG目前我已将其修复并进行了测试。 4.对Win32环境下的GetAvailablePorts函数进行重写,现在可以获取串口号超过20的串口(原来的最多到Com20),并且可以得到串口的设备名信息。 5.以上修改只在Windows下测试通过,我手头没有Linux环境,对Linux相关的代码基本是靠着意念盲改,如果您发现了有错误疏漏,欢迎指正,能帮我改改就更好了,比如Linux下如何取得串口设备名我就还没弄明白。 压缩包里有可以编译静态库的工程,以及一个基于wxWidgets3.1的演示工程,就是一个简单的串口收发器,供大家参考。 由于串口功能的实现需要依赖Windows系统API,在Windows下,如果使用Mingw编译,请改你连·请关联静态库libsetupapi.a与libwinmm.a
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值