侯体宗的博客
  • 首页
  • Hyperf版
  • beego仿版
  • 人生(杂谈)
  • 技术
  • 关于我
  • 更多分类
    • 文件下载
    • 文字修仙
    • 中国象棋ai
    • 群聊
    • 九宫格抽奖
    • 拼图
    • 消消乐
    • 相册

ubuntu 13.10编译安装mono环境(二)

linux  /  管理员 发布于 5年前   522

准备工作

先在VS2012上编译一个winform,代码如下:

using System;using System.Windows.Forms;namespace FormsTest{static class Program{/// <summary>/// 应用程序的主入口点。/// </summary>[STAThread]static void Main(){Application.EnableVisualStyles();Application.SetCompatibleTextRenderingDefault(false);Application.Run(new Form());}}}

尝试在ubuntu上用mono运行:

nike@NIKE-PC:~$ cd Desktop/nike@NIKE-PC:~/Desktop$ lsFormsTest.exenike@NIKE-PC:~/Desktop$ mono FormsTest.exeUnhandled Exception:System.TypeInitializationException: An exception was thrown by the type initializer for System.Windows.Forms.XplatUI ---> System.TypeInitializationException: An exception was thrown by the type initializer for System.Drawing.GDIPlus ---> System.DllNotFoundException: /opt/mono-3.2.8/lib/libgdiplus.soat (wrapper managed-to-native) System.Drawing.GDIPlus:GdiplusStartup (ulong&,System.Drawing.GdiplusStartupInput&,System.Drawing.GdiplusStartupOutput&)at System.Drawing.GDIPlus..cctor () [0x00000] in <filename unknown>:0--- End of inner exception stack trace ---at System.Drawing.Graphics.FromHdcInternal (IntPtr hdc) [0x00000] in <filename unknown>:0at System.Windows.Forms.XplatUIX11.SetDisplay (IntPtr display_handle) [0x00000] in <filename unknown>:0at System.Windows.Forms.XplatUIX11..ctor () [0x00000] in <filename unknown>:0at System.Windows.Forms.XplatUIX11.GetInstance () [0x00000] in <filename unknown>:0at System.Windows.Forms.XplatUI..cctor () [0x00000] in <filename unknown>:0--- End of inner exception stack trace ---at System.Windows.Forms.Application.EnableVisualStyles () [0x00000] in <filename unknown>:0at FormsTest.Program.Main () [0x00000] in <filename unknown>:0[ERROR] FATAL UNHANDLED EXCEPTION: System.TypeInitializationException: An exception was thrown by the type initializer for System.Windows.Forms.XplatUI ---> System.TypeInitializationException: An exception was thrown by the type initializer for System.Drawing.GDIPlus ---> System.DllNotFoundException: /opt/mono-3.2.8/lib/libgdiplus.soat (wrapper managed-to-native) System.Drawing.GDIPlus:GdiplusStartup (ulong&,System.Drawing.GdiplusStartupInput&,System.Drawing.GdiplusStartupOutput&)at System.Drawing.GDIPlus..cctor () [0x00000] in <filename unknown>:0--- End of inner exception stack trace ---at System.Drawing.Graphics.FromHdcInternal (IntPtr hdc) [0x00000] in <filename unknown>:0at System.Windows.Forms.XplatUIX11.SetDisplay (IntPtr display_handle) [0x00000] in <filename unknown>:0at System.Windows.Forms.XplatUIX11..ctor () [0x00000] in <filename unknown>:0at System.Windows.Forms.XplatUIX11.GetInstance () [0x00000] in <filename unknown>:0at System.Windows.Forms.XplatUI..cctor () [0x00000] in <filename unknown>:0--- End of inner exception stack trace ---at System.Windows.Forms.Application.EnableVisualStyles () [0x00000] in <filename unknown>:0at FormsTest.Program.Main () [0x00000] in <filename unknown>:0

遇到错误了System.DllNotFoundException: /opt/mono-3.2.8/lib/libgdiplus.so,原因是如果要在ubuntu运行winform,那么必须要安装libgdiplus。

下载libgdiplus并编译

nike@NIKE-PC:~$ cd srcnike@NIKE-PC:~/src$ wget http://download.mono-project.com/sources/libgdiplus/libgdiplus-2.10.9.tar.bz2--2014-03-27 22:46:40-- http://download.mono-project.com/sources/libgdiplus/libgdiplus-2.10.9.tar.bz2Resolving download.mono-project.com (download.mono-project.com)... 54.230.157.116, 54.230.157.204, 54.230.158.216, ...Connecting to download.mono-project.com (download.mono-project.com)|54.230.157.116|:80... connected.HTTP request sent, awaiting response... 200 OKLength: 2074317 (2.0M) [application/x-bzip2]Saving to: ‘libgdiplus-2.10.9.tar.bz2' 100%[======================================>] 2,074,317 224KB/s in 9.5s 2014-03-27 22:46:54 (213 KB/s) - ‘libgdiplus-2.10.9.tar.bz2' saved [2074317/2074317] nike@NIKE-PC:~/src$ lslibgdiplus-2.10.9.tar.bz2 mono-3.2.8 mono-3.2.8.tar.bz2nike@NIKE-PC:~/src$ tar -xvjf libgdiplus-2.10.9.tar.bz2nike@NIKE-PC:~/src$ cd libgdiplus-2.10.9/nike@NIKE-PC:~/src/libgdiplus-2.10.9$ ./configure --prefix=/opt/mono-3.2.8==============>省略了很多<==============checking pkg-config is at least version 0.9.0... yeschecking for BASE_DEPENDENCIES... noconfigure: error: Package requirements (glib-2.0 >= 2.2.3) were not met:No package 'glib-2.0' foundConsider adjusting the PKG_CONFIG_PATH environment variable if youinstalled software in a non-standard prefix. Alternatively, you may set the environment variables BASE_DEPENDENCIES_CFLAGSand BASE_DEPENDENCIES_LIBS to avoid the need to call pkg-config.See the pkg-config man page for more details.

遇到错误了,需要安装libglib2.0-dev:

nike@NIKE-PC:~/src/libgdiplus-2.10.9$ sudo apt-get install libglib2.0-devReading package lists... DoneBuilding dependency treeReading state information... DoneThe following extra packages will be installed:libglib2.0-0 libglib2.0-bin libpcre3-dev libpcrecpp0 zlib1g-devSuggested packages:libglib2.0-docThe following NEW packages will be installed:libglib2.0-dev libpcre3-dev libpcrecpp0 zlib1g-devThe following packages will be upgraded:libglib2.0-0 libglib2.0-bin2 upgraded, 4 newly installed, 0 to remove and 273 not upgraded.Need to get 2,728 kB of archives.After this operation, 9,208 kB of additional disk space will be used.Do you want to continue [Y/n]?==============>省略了很多<==============

重新初始化libgdiplus安装配置文件:

nike@NIKE-PC:~/src/libgdiplus-2.10.9$ ./configure --prefix=/opt/mono-3.2.8==============>省略了很多<==============checking for libpng14... checking for libpng12... nochecking for png_read_info in -lpng... noconfigure: error: *** libpng12 not found. See http://www.libpng.org/pub/png/libpng.html.

又遇到错误了,需要安装libpng-dev:

nike@NIKE-PC:~/src/libgdiplus-2.10.9$ sudo apt-get install libpng-dev

重新初始化libgdiplus安装配置文件:

nike@NIKE-PC:~/src/libgdiplus-2.10.9$ ./configure --prefix=/opt/mono-3.2.8==============>省略了很多<==============./configure: line 13371: test: too many argumentsconfigure: error: "Failed to compile with X11/Xlib.h include. You must fix your compiler paths"

提示错误,需要安装libx11-dev:

nike@NIKE-PC:~/src/libgdiplus-2.10.9$ sudo apt-get install libx11-dev

重新初始化libgdiplus安装配置文件:

nike@NIKE-PC:~/src/libgdiplus-2.10.9$ ./configure --prefix=/opt/mono-3.2.8==============>省略了很多<==============configure: error: Cairo requires at least one font backend.Please install freetype and fontconfig, then try again:http://freetype.org/ http://fontconfig.org/configure: error: ./configure failed for cairo

需要安装freetype和fontconfig:

nike@NIKE-PC:~/src/libgdiplus-2.10.9$ sudo apt-get install libfreetype6-devnike@NIKE-PC:~/src/libgdiplus-2.10.9$ sudo apt-get install fontconfignike@NIKE-PC:~/src/libgdiplus-2.10.9$ sudo apt-get install libfontconfig1-dev

重新初始化libgdiplus安装配置文件:

nike@NIKE-PC:~/src/libgdiplus-2.10.9$ ./configure --prefix=/opt/mono-3.2.8==============>省略了很多<==============Configuration summary * Installation prefix = /opt/mono-3.2.8* Cairo = 1.6.4 (internal)* Text = cairo* EXIF tags = No. Get it from http://libexif.sourceforge.net/* Codecs supported: - TIFF: no (Get it from http://www.libtiff.org/)- JPEG: no (Get it from http://freshmeat.net/projects/libjpeg)- GIF: no (See http://sourceforge.net/projects/libgif)- PNG: yes NOTE: if any of the above say 'no' you may install thecorresponding development packages for them, rerunautogen.sh to include them in the build.nike@NIKE-PC:

./configure通过。

编译安装源代码

nike@NIKE-PC:~/src/libgdiplus-2.10.9$ makemake all-recursivemake[1]: Entering directory `/home/nike/src/libgdiplus-2.10.9'Making all in pixmanmake[2]: Entering directory `/home/nike/src/libgdiplus-2.10.9/pixman'make all-recursivemake[3]: Entering directory `/home/nike/src/libgdiplus-2.10.9/pixman'Making all in pixmanmake[4]: Entering directory `/home/nike/src/libgdiplus-2.10.9/pixman/pixman'/bin/bash ../libtool --tag=CC --mode=compile gcc -DHAVE_CONFIG_H -I. -I.. -g -O2 -Wall -fvisibility=hidden -MT pixman-access.lo -MD -MP -MF .deps/pixman-access.Tpo -c -o pixman-access.lo pixman-access.c../libtool: line 852: X--tag=CC: command not found

遇到错误了,通过google搜索,可能是因为在项目目录下生成的libtool脚本中定义了$ECHO变量,但是在脚本文件ltmain.sh中,使用的却是$echo(生成的libtool版本太旧) 解决方法很简单export echo=echo即可:

nike@NIKE-PC:~/src/libgdiplus-2.10.9$ export echo=echonike@NIKE-PC:~/src/libgdiplus-2.10.9$ make==============>省略了很多<==============make[2]: Entering directory `/home/nike/src/libgdiplus-2.10.9/tests'/bin/bash ../libtool --tag=CC --mode=link gcc -g -O2 -pthread -o testgdi testgdi.o ../src/libgdiplus.la -lpthread -lfontconfiglibtool: link: gcc -g -O2 -pthread -o .libs/testgdi testgdi.o ../src/.libs/libgdiplus.so -lpthread -lfontconfig -pthread -Wl,-rpath -Wl,/opt/mono-3.2.8/lib/usr/bin/ld: testgdi.o: undefined reference to symbol 'g_print'/lib/i386-linux-gnu/libglib-2.0.so.0: error adding symbols: DSO missing from command linecollect2: error: ld returned 1 exit statusmake[2]: *** [testgdi] Error 1make[2]: Leaving directory `/home/nike/src/libgdiplus-2.10.9/tests'make[1]: *** [all-recursive] Error 1make[1]: Leaving directory `/home/nike/src/libgdiplus-2.10.9'make: *** [all] Error 2

编译时又出错了,解决办法为: 1.运行./configure后,编辑tests/Makefile文件 2.在Makefile文件130行位置,将LIBS = -lpthread -lfontconfig改为LIBS = -lpthread -lfontconfig -lglib-2.0 -lX11 3.再次运行make即可

nike@NIKE-PC:~/src/libgdiplus-2.10.9$ vim tests/Makefilenike@NIKE-PC:~/src/libgdiplus-2.10.9$ make==============>编译很快<==============nike@NIKE-PC:~/src/libgdiplus-2.10.9$ sudo make install==============>省略了很多<==============

安装完成。

设置PATH环境变量

nike@NIKE-PC:~/src/mono-3.2.8$ cd ~nike@NIKE-PC:~$ vim .bashrc

在该文件末尾追加以下语句: export LD_LIBRARY_PATH=/opt/mono-3.2.8/lib 然后:

nike@NIKE-PC:~$ . .bashrcnike@NIKE-PC:~$ echo $LD_LIBRARY_PATH/opt/mono-3.2.8/libnike@NIKE-PC:~$

验证libgdiplus是否安装成功

nike@NIKE-PC:~$ cd Desktop/nike@NIKE-PC:~/Desktop$ mono FormsTest.exe


运行成功。


  • 上一条:
    Ubuntu下如何设置ssh免密码登录安装
    下一条:
    ubuntu13.10编译安装mono环境(一)
  • 昵称:

    邮箱:

    0条评论 (评论内容有缓存机制,请悉知!)
    最新最热
    • 分类目录
    • 人生(杂谈)
    • 技术
    • linux
    • Java
    • php
    • 框架(架构)
    • 前端
    • ThinkPHP
    • 数据库
    • 微信(小程序)
    • Laravel
    • Redis
    • Docker
    • Go
    • swoole
    • Windows
    • Python
    • 苹果(mac/ios)
    • 相关文章
    • 在Linux系统中使用Iptables实现流量转发功能流程步骤(0个评论)
    • vim学习笔记-入门级需要了解的一些快捷键(0个评论)
    • 在centos7系统中实现分区并格式化挂载一块硬盘到/data目录流程步骤(0个评论)
    • 在Linux系统种查看某一个进程所占用的内存命令(0个评论)
    • Linux中grep命令中的10种高级用法浅析(0个评论)
    • 近期文章
    • 智能合约Solidity学习CryptoZombie第三课:组建僵尸军队(高级Solidity理论)(0个评论)
    • 智能合约Solidity学习CryptoZombie第二课:让你的僵尸猎食(0个评论)
    • 智能合约Solidity学习CryptoZombie第一课:生成一只你的僵尸(0个评论)
    • 在go中实现一个常用的先进先出的缓存淘汰算法示例代码(0个评论)
    • 在go+gin中使用"github.com/skip2/go-qrcode"实现url转二维码功能(0个评论)
    • 在go语言中使用api.geonames.org接口实现根据国际邮政编码获取地址信息功能(1个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf分页文件功能(0个评论)
    • gmail发邮件报错:534 5.7.9 Application-specific password required...解决方案(0个评论)
    • 欧盟关于强迫劳动的规定的官方举报渠道及官方举报网站(0个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf文件功能(0个评论)
    • 近期评论
    • 122 在

      学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..
    • 123 在

      Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..
    • 原梓番博客 在

      在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..
    • 博主 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..
    • 1111 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
    • 2016-11
    • 2017-07
    • 2017-10
    • 2017-11
    • 2018-01
    • 2018-02
    • 2020-03
    • 2020-04
    • 2020-05
    • 2020-06
    • 2021-02
    • 2021-03
    • 2021-04
    • 2021-06
    • 2021-07
    • 2021-08
    • 2021-09
    • 2021-10
    • 2021-11
    • 2021-12
    • 2022-01
    • 2022-03
    • 2022-04
    • 2022-08
    • 2022-11
    • 2022-12
    • 2023-01
    • 2023-02
    • 2023-03
    • 2023-06
    • 2023-07
    • 2023-10
    • 2023-12
    • 2024-01
    • 2024-04
    Top

    Copyright·© 2019 侯体宗版权所有· 粤ICP备20027696号 PHP交流群

    侯体宗的博客