ubuntu 13.10编译安装mono环境(二)
准备工作
先在VS2012上编译一个winform,代码如下:
usingSystem; usingSystem.Windows.Forms; namespaceFormsTest { staticclassProgram { ///<summary> ///应用程序的主入口点。 ///</summary> [STAThread] staticvoidMain() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(newForm()); } } }
尝试在ubuntu上用mono运行:
nike@NIKE-PC:~$cdDesktop/ nike@NIKE-PC:~/Desktop$ls FormsTest.exe nike@NIKE-PC:~/Desktop$monoFormsTest.exe UnhandledException: System.TypeInitializationException:AnexceptionwasthrownbythetypeinitializerforSystem.Windows.Forms.XplatUI--->System.TypeInitializationException:AnexceptionwasthrownbythetypeinitializerforSystem.Drawing.GDIPlus--->System.DllNotFoundException:/opt/mono-3.2.8/lib/libgdiplus.so at(wrappermanaged-to-native)System.Drawing.GDIPlus:GdiplusStartup(ulong&,System.Drawing.GdiplusStartupInput&,System.Drawing.GdiplusStartupOutput&) atSystem.Drawing.GDIPlus..cctor()[0x00000]in<filenameunknown>:0 ---Endofinnerexceptionstacktrace--- atSystem.Drawing.Graphics.FromHdcInternal(IntPtrhdc)[0x00000]in<filenameunknown>:0 atSystem.Windows.Forms.XplatUIX11.SetDisplay(IntPtrdisplay_handle)[0x00000]in<filenameunknown>:0 atSystem.Windows.Forms.XplatUIX11..ctor()[0x00000]in<filenameunknown>:0 atSystem.Windows.Forms.XplatUIX11.GetInstance()[0x00000]in<filenameunknown>:0 atSystem.Windows.Forms.XplatUI..cctor()[0x00000]in<filenameunknown>:0 ---Endofinnerexceptionstacktrace--- atSystem.Windows.Forms.Application.EnableVisualStyles()[0x00000]in<filenameunknown>:0 atFormsTest.Program.Main()[0x00000]in<filenameunknown>:0 [ERROR]FATALUNHANDLEDEXCEPTION:System.TypeInitializationException:AnexceptionwasthrownbythetypeinitializerforSystem.Windows.Forms.XplatUI--->System.TypeInitializationException:AnexceptionwasthrownbythetypeinitializerforSystem.Drawing.GDIPlus--->System.DllNotFoundException:/opt/mono-3.2.8/lib/libgdiplus.so at(wrappermanaged-to-native)System.Drawing.GDIPlus:GdiplusStartup(ulong&,System.Drawing.GdiplusStartupInput&,System.Drawing.GdiplusStartupOutput&) atSystem.Drawing.GDIPlus..cctor()[0x00000]in<filenameunknown>:0 ---Endofinnerexceptionstacktrace--- atSystem.Drawing.Graphics.FromHdcInternal(IntPtrhdc)[0x00000]in<filenameunknown>:0 atSystem.Windows.Forms.XplatUIX11.SetDisplay(IntPtrdisplay_handle)[0x00000]in<filenameunknown>:0 atSystem.Windows.Forms.XplatUIX11..ctor()[0x00000]in<filenameunknown>:0 atSystem.Windows.Forms.XplatUIX11.GetInstance()[0x00000]in<filenameunknown>:0 atSystem.Windows.Forms.XplatUI..cctor()[0x00000]in<filenameunknown>:0 ---Endofinnerexceptionstacktrace--- atSystem.Windows.Forms.Application.EnableVisualStyles()[0x00000]in<filenameunknown>:0 atFormsTest.Program.Main()[0x00000]in<filenameunknown>:0
遇到错误了System.DllNotFoundException:/opt/mono-3.2.8/lib/libgdiplus.so,原因是如果要在ubuntu运行winform,那么必须要安装libgdiplus。
下载libgdiplus并编译
nike@NIKE-PC:~$cdsrc nike@NIKE-PC:~/src$wgethttp://download.mono-project.com/sources/libgdiplus/libgdiplus-2.10.9.tar.bz2 --2014-03-2722:46:40--http://download.mono-project.com/sources/libgdiplus/libgdiplus-2.10.9.tar.bz2 Resolvingdownload.mono-project.com(download.mono-project.com)...54.230.157.116,54.230.157.204,54.230.158.216,... Connectingtodownload.mono-project.com(download.mono-project.com)|54.230.157.116|:80...connected. HTTPrequestsent,awaitingresponse...200OK Length:2074317(2.0M)[application/x-bzip2] Savingto:‘libgdiplus-2.10.9.tar.bz2' 100%[======================================>]2,074,317224KB/sin9.5s 2014-03-2722:46:54(213KB/s)-‘libgdiplus-2.10.9.tar.bz2'saved[2074317/2074317] nike@NIKE-PC:~/src$ls libgdiplus-2.10.9.tar.bz2mono-3.2.8mono-3.2.8.tar.bz2 nike@NIKE-PC:~/src$tar-xvjflibgdiplus-2.10.9.tar.bz2 nike@NIKE-PC:~/src$cdlibgdiplus-2.10.9/ nike@NIKE-PC:~/src/libgdiplus-2.10.9$./configure--prefix=/opt/mono-3.2.8 ==============>省略了很多<============== checkingpkg-configisatleastversion0.9.0...yes checkingforBASE_DEPENDENCIES...no configure:error:Packagerequirements(glib-2.0>=2.2.3)werenotmet: Nopackage'glib-2.0'found ConsideradjustingthePKG_CONFIG_PATHenvironmentvariableifyou installedsoftwareinanon-standardprefix. Alternatively,youmaysettheenvironmentvariablesBASE_DEPENDENCIES_CFLAGS andBASE_DEPENDENCIES_LIBStoavoidtheneedtocallpkg-config. Seethepkg-configmanpageformoredetails.
遇到错误了,需要安装libglib2.0-dev:
nike@NIKE-PC:~/src/libgdiplus-2.10.9$sudoapt-getinstalllibglib2.0-dev Readingpackagelists...Done Buildingdependencytree Readingstateinformation...Done Thefollowingextrapackageswillbeinstalled: libglib2.0-0libglib2.0-binlibpcre3-devlibpcrecpp0zlib1g-dev Suggestedpackages: libglib2.0-doc ThefollowingNEWpackageswillbeinstalled: libglib2.0-devlibpcre3-devlibpcrecpp0zlib1g-dev Thefollowingpackageswillbeupgraded: libglib2.0-0libglib2.0-bin 2upgraded,4newlyinstalled,0toremoveand273notupgraded. Needtoget2,728kBofarchives. Afterthisoperation,9,208kBofadditionaldiskspacewillbeused. Doyouwanttocontinue[Y/n]? ==============>省略了很多<==============
重新初始化libgdiplus安装配置文件:
nike@NIKE-PC:~/src/libgdiplus-2.10.9$./configure--prefix=/opt/mono-3.2.8 ==============>省略了很多<============== checkingforlibpng14...checkingforlibpng12...no checkingforpng_read_infoin-lpng...no configure:error:***libpng12notfound.Seehttp://www.libpng.org/pub/png/libpng.html.
又遇到错误了,需要安装libpng-dev:
nike@NIKE-PC:~/src/libgdiplus-2.10.9$sudoapt-getinstalllibpng-dev
重新初始化libgdiplus安装配置文件:
nike@NIKE-PC:~/src/libgdiplus-2.10.9$./configure--prefix=/opt/mono-3.2.8 ==============>省略了很多<============== ./configure:line13371:test:toomanyarguments configure:error:"FailedtocompilewithX11/Xlib.hinclude.Youmustfixyourcompilerpaths"
提示错误,需要安装libx11-dev:
nike@NIKE-PC:~/src/libgdiplus-2.10.9$sudoapt-getinstalllibx11-dev
重新初始化libgdiplus安装配置文件:
nike@NIKE-PC:~/src/libgdiplus-2.10.9$./configure--prefix=/opt/mono-3.2.8 ==============>省略了很多<============== configure:error:Cairorequiresatleastonefontbackend. Pleaseinstallfreetypeandfontconfig,thentryagain: http://freetype.org/http://fontconfig.org/ configure:error:./configurefailedforcairo
需要安装freetype和fontconfig:
nike@NIKE-PC:~/src/libgdiplus-2.10.9$sudoapt-getinstalllibfreetype6-dev nike@NIKE-PC:~/src/libgdiplus-2.10.9$sudoapt-getinstallfontconfig nike@NIKE-PC:~/src/libgdiplus-2.10.9$sudoapt-getinstalllibfontconfig1-dev
重新初始化libgdiplus安装配置文件:
nike@NIKE-PC:~/src/libgdiplus-2.10.9$./configure--prefix=/opt/mono-3.2.8 ==============>省略了很多<============== Configurationsummary *Installationprefix=/opt/mono-3.2.8 *Cairo=1.6.4(internal) *Text=cairo *EXIFtags=No.Getitfromhttp://libexif.sourceforge.net/ *Codecssupported: -TIFF:no(Getitfromhttp://www.libtiff.org/) -JPEG:no(Getitfromhttp://freshmeat.net/projects/libjpeg) -GIF:no(Seehttp://sourceforge.net/projects/libgif) -PNG:yes NOTE:ifanyoftheabovesay'no'youmayinstallthe correspondingdevelopmentpackagesforthem,rerun autogen.shtoincludetheminthebuild. nike@NIKE-PC:
./configure通过。
编译安装源代码
nike@NIKE-PC:~/src/libgdiplus-2.10.9$make makeall-recursive make[1]:Enteringdirectory`/home/nike/src/libgdiplus-2.10.9' Makingallinpixman make[2]:Enteringdirectory`/home/nike/src/libgdiplus-2.10.9/pixman' makeall-recursive make[3]:Enteringdirectory`/home/nike/src/libgdiplus-2.10.9/pixman' Makingallinpixman make[4]:Enteringdirectory`/home/nike/src/libgdiplus-2.10.9/pixman/pixman' /bin/bash../libtool--tag=CC--mode=compilegcc-DHAVE_CONFIG_H-I.-I..-g-O2-Wall-fvisibility=hidden-MTpixman-access.lo-MD-MP-MF.deps/pixman-access.Tpo-c-opixman-access.lopixman-access.c ../libtool:line852:X--tag=CC:commandnotfound
遇到错误了,通过google搜索,可能是因为在项目目录下生成的libtool脚本中定义了$ECHO变量,但是在脚本文件ltmain.sh中,使用的却是$echo(生成的libtool版本太旧)解决方法很简单exportecho=echo即可:
nike@NIKE-PC:~/src/libgdiplus-2.10.9$exportecho=echo nike@NIKE-PC:~/src/libgdiplus-2.10.9$make ==============>省略了很多<============== make[2]:Enteringdirectory`/home/nike/src/libgdiplus-2.10.9/tests' /bin/bash../libtool--tag=CC--mode=linkgcc-g-O2-pthread-otestgditestgdi.o../src/libgdiplus.la-lpthread-lfontconfig libtool:link:gcc-g-O2-pthread-o.libs/testgditestgdi.o../src/.libs/libgdiplus.so-lpthread-lfontconfig-pthread-Wl,-rpath-Wl,/opt/mono-3.2.8/lib /usr/bin/ld:testgdi.o:undefinedreferencetosymbol'g_print' /lib/i386-linux-gnu/libglib-2.0.so.0:erroraddingsymbols:DSOmissingfromcommandline collect2:error:ldreturned1exitstatus make[2]:***[testgdi]Error1 make[2]:Leavingdirectory`/home/nike/src/libgdiplus-2.10.9/tests' make[1]:***[all-recursive]Error1 make[1]:Leavingdirectory`/home/nike/src/libgdiplus-2.10.9' make:***[all]Error2
编译时又出错了,解决办法为:1.运行./configure后,编辑tests/Makefile文件2.在Makefile文件130行位置,将LIBS=-lpthread-lfontconfig改为LIBS=-lpthread-lfontconfig-lglib-2.0-lX113.再次运行make即可
nike@NIKE-PC:~/src/libgdiplus-2.10.9$vimtests/Makefile nike@NIKE-PC:~/src/libgdiplus-2.10.9$make ==============>编译很快<============== nike@NIKE-PC:~/src/libgdiplus-2.10.9$sudomakeinstall ==============>省略了很多<==============
安装完成。
设置PATH环境变量
nike@NIKE-PC:~/src/mono-3.2.8$cd~ nike@NIKE-PC:~$vim.bashrc
在该文件末尾追加以下语句:exportLD_LIBRARY_PATH=/opt/mono-3.2.8/lib然后:
nike@NIKE-PC:~$..bashrc nike@NIKE-PC:~$echo$LD_LIBRARY_PATH /opt/mono-3.2.8/lib nike@NIKE-PC:~$
验证libgdiplus是否安装成功
nike@NIKE-PC:~$cdDesktop/ nike@NIKE-PC:~/Desktop$monoFormsTest.exe
运行成功。