其实网上wxWidgets编译相关的博文,都没写到关键点上,泛泛而谈——就写了执行几个命令,就万事大吉了! 维基百科上的这个页面讲解了编译中可能遇到的各种问题及解决办法。比较懒,不想翻译。wxWidgets中文资料不多,英文的帮助、开发手册、书籍比较全面细致,如果要用wxWidgets就不得不阅读这些英文资料。如果编译wxWidgets的英文文档都看不懂,还是不要用wxWidgets算了。我以前用MFC、WinForm、WPF做Windows界面,但是跨不了平台;虽然.net这回真正开源了,但是WinForm和WPF的移植计划还没摆上台面。此外WinForm应该不会移植到Linux上了,WinForm的实现依赖了windows内核中对图形界面以及消息的处理。wxWidgets与MFC在消息处理、对话框模式图形程序、Frame-View-Document模式图形程序等方面比较像。此外wxWidgets更加灵活,也更加面向对象,没有那么多宏、那么#define常量;事件及事件参数的处理更像WinForm;wxWidgets还支持界面布局。所以决定学学wxWidgets,知识跨度也不大。
我在编译中就遇到了两个问题。
第一,MinGW默认用自带的sh.exe这个SHELL
mingw32-make -f makefile.gcc BUILD=release UNICODE=1 SHARED=0
sh.exe跟windows命令行的很多语法和内置命令不一样。所以直接用上面的命令会出现“找不到指定的文件”的问题。
这个的解决版本就是把其它版本的MinGW和MYSYS从系统的Path变量中去除,只留下要用一个。同时要在编译命令中加上SHELL=CMD.exe.
mingw32-make SHELL=CMD.exe -f makefile.gcc BUILD=release UNICODE=1 SHARED=0
第二,编译到最后,链接的时候出现“输入行太长”。
下面是我编译过程中出现问题的命令。
ar rcu C:\wxWidgets\lib\gcc_lib\libwxmsw30ud_core.a corelib_dummy.o corelib_event.o corelib_fs_mem.o corelib_msgout.o corelib_utilscmn.o corelib_main.o corelib_mslu.o corelib_volume.o corelib_activex.o corelib_app.o corelib_bitmap.o corelib_brush.o corelib_caret.o corelib_clipbrd.o corelib_colour.o corelib_cursor.o corelib_data.o corelib_dc.o corelib_dcclient.o corelib_dcmemory.o corelib_dcprint.o corelib_dcscreen.o corelib_dialup.o corelib_dib.o corelib_display.o corelib_enhmeta.o corelib_font.o corelib_fontenum.o corelib_fontutil.o corelib_gdiimage.o corelib_gdiobj.o corelib_gdiplus.o corelib_graphics.o corelib_icon.o corelib_imaglist.o corelib_minifram.o corelib_nonownedwnd.o corelib_dataobj.o corelib_dropsrc.o corelib_droptgt.o corelib_oleutils.o corelib_safearray.o corelib_palette.o corelib_pen.o corelib_popupwin.o corelib_printdlg.o corelib_printwin.o corelib_region.o corelib_renderer.o corelib_settings.o corelib_textmeasure.o corelib_tooltip.o corelib_toplevel.o corelib_uiaction.o corelib_utilsgui.o corelib_utilswin.o corelib_uxtheme.o corelib_window.o corelib_helpchm.o corelib_helpwin.o corelib_automtn.o corelib_uuid.o corelib_clrpickerg.o corelib_collpaneg.o corelib_filepickerg.o corelib_fontpickerg.o corelib_generic_statusbr.o corelib_prntdlgg.o corelib_msw_accel.o corelib_anybutton.o corelib_artmsw.o corelib_msw_bmpbuttn.o corelib_msw_button.o corelib_msw_checkbox.o corelib_msw_choice.o corelib_colordlg.o corelib_combo.o corelib_msw_combobox.o corelib_msw_control.o corelib_msw_dialog.o corelib_dirdlg.o corelib_dragimag.o corelib_evtloop.o corelib_filedlg.o corelib_frame.o corelib_msw_gauge.o corelib_headerctrl.o corelib_iniconf.o corelib_msw_listbox.o corelib_msw_listctrl.o corelib_mdi.o corelib_msw_menu.o corelib_menuitem.o corelib_metafile.o corelib_msgdlg.o corelib_nativdlg.o corelib_nativewin.o corelib_msw_notebook.o corelib_access.o corelib_ownerdrw.o corelib_panel.o corelib_progdlg.o corelib_msw_radiobox.o corelib_msw_radiobut.o corelib_richmsgdlg.o corelib_msw_scrolbar.o corelib_msw_slider.o corelib_msw_spinbutt.o corelib_spinctrl.o corelib_msw_statbmp.o corelib_msw_statbox.o corelib_statusbar.o corelib_msw_statline.o corelib_msw_stattext.o corelib_msw_toolbar.o corelib_msw_textctrl.o corelib_textentry.o corelib_msw_tglbtn.o corelib_treectrl.o corelib_msw_checklst.o corelib_msw_fdrepdlg.o corelib_fontdlg.o corelib_accelcmn.o corelib_accesscmn.o corelib_anidecod.o corelib_affinematrix2d.o corelib_appcmn.o corelib_artprov.o corelib_artstd.o corelib_arttango.o corelib_bmpbase.o corelib_bmpbtncmn.o corelib_bookctrl.o corelib_btncmn.o corelib_cairo.o corelib_checkboxcmn.o corelib_checklstcmn.o corelib_choiccmn.o corelib_clipcmn.o corelib_clrpickercmn.o corelib_colourcmn.o corelib_colourdata.o corelib_combocmn.o corelib_cmdproc.o corelib_cmndata.o corelib_containr.o corelib_cshelp.o corelib_ctrlcmn.o corelib_ctrlsub.o corelib_dcbase.o corelib_dcbufcmn.o corelib_dcgraph.o corelib_dcsvg.o corelib_dirctrlcmn.o corelib_dlgcmn.o corelib_dndcmn.o corelib_dobjcmn.o corelib_docmdi.o corelib_docview.o corelib_dpycmn.o corelib_dseldlg.o corelib_effects.o corelib_fddlgcmn.o corelib_filectrlcmn.o corelib_filehistorycmn.o corelib_filepickercmn.o corelib_fontpickercmn.o corelib_fldlgcmn.o corelib_fontcmn.o corelib_fontdata.o corelib_graphicc.o corelib_fontenumcmn.o corelib_fontmap.o corelib_fontutilcmn.o corelib_framecmn.o corelib_gaugecmn.o corelib_gbsizer.o corelib_gdicmn.o corelib_geometry.o corelib_gifdecod.o corelib_graphcmn.o corelib_headercolcmn.o corelib_headerctrlcmn.o corelib_helpbase.o corelib_iconbndl.o corelib_imagall.o corelib_imagbmp.o corelib_image.o corelib_imagfill.o corelib_imaggif.o corelib_imagiff.o corelib_imagjpeg.o corelib_imagpcx.o corelib_imagpng.o corelib_imagpnm.o corelib_imagtga.o corelib_imagtiff.o corelib_imagxpm.o corelib_layout.o corelib_lboxcmn.o corelib_listctrlcmn.o corelib_markupparser.o corelib_matrix.o corelib_menucmn.o corelib_modalhook.o corelib_mousemanager.o corelib_nbkbase.o corelib_overlaycmn.o corelib_ownerdrwcmn.o corelib_paper.o corelib_panelcmn.o corelib_persist.o corelib_pickerbase.o corelib_popupcmn.o corelib_preferencescmn.o corelib_prntbase.o corelib_quantize.o corelib_radiobtncmn.o corelib_radiocmn.o corelib_rearrangectrl.o corelib_rendcmn.o corelib_rgncmn.o corelib_scrolbarcmn.o corelib_settcmn.o corelib_sizer.o corelib_slidercmn.o corelib_spinbtncmn.o corelib_spinctrlcmn.o corelib_srchcmn.o corelib_statbar.o corelib_statbmpcmn.o corelib_statboxcmn.o corelib_statlinecmn.o corelib_stattextcmn.o corelib_stockitem.o corelib_tbarbase.o corelib_textcmn.o corelib_textentrycmn.o corelib_textmeasurecmn.o corelib_toplvcmn.o corelib_treebase.o corelib_uiactioncmn.o corelib_valgen.o corelib_validate.o corelib_valtext.o corelib_valnum.o corelib_wincmn.o corelib_windowid.o corelib_wrapsizer.o corelib_xpmdecod.o corelib_busyinfo.o corelib_buttonbar.o corelib_choicdgg.o corelib_choicbkg.o corelib_combog.o corelib_dcpsg.o corelib_dirctrlg.o corelib_dragimgg.o corelib_filectrlg.o corelib_headerctrlg.o corelib_infobar.o corelib_listbkg.o corelib_logg.o corelib_markuptext.o corelib_msgdlgg.o corelib_numdlgg.o corelib_progdlgg.o corelib_preferencesg.o corelib_printps.o corelib_renderg.o corelib_richmsgdlgg.o corelib_scrlwing.o corelib_selstore.o corelib_spinctlg.o corelib_splitter.o corelib_srchctlg.o corelib_statbmpg.o corelib_stattextg.o corelib_textdlgg.o corelib_tipwin.o corelib_toolbkg.o corelib_treectlg.o corelib_treebkg.o corelib_vlbox.o corelib_vscroll.o corelib_xmlreshandler.o
要不编译出来的n多obj文件链接成libwxmsw30ud_core.a库,这个命令超过windows命令行要求的最长命令了,所以执行不了。上面的命令还是我手动修改过的,要不然更长,这就已经一页word文档放不下了。
这个问题的解决应该灵活处理,维基上说Replace $(MONOLIB_OBJECTS) with gcc_mswu\monolib*.o。这是编译成一个库的时候这个地方肯定会出现问题。但是我还是编译成分散的库,而是在链接libwxmsw30ud_core.a时出现的问题。那么改法就不一样了。
在下面那个地方把$(CORELIB_OBJECTS)替换成gcc_mswud\corelib*.o。注意目录名和文件名前缀,我是在编译debug版本时出现的问题,所以目录是gcc_mswud。注意编译完成之后再替换回来,如果不替换release版本也从debug版本的目录中找obj文件进行链接了。
makefile中定义了 $(BASELIB_OBJECTS)、$(NETLIB_OBJECTS)、$(CORELIB_OBJECTS)、$(MONOLIB_OBJECTS),那个出问题了改那个,不要死抄。