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

准备工作

先在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$ ls
FormsTest.exe
nike@NIKE-PC:~/Desktop$ mono FormsTest.exe
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.so
at (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>:0
at System.Windows.Forms.XplatUIX11.SetDisplay (IntPtr display_handle) [0x00000] in <filename unknown>:0
at System.Windows.Forms.XplatUIX11..ctor () [0x00000] in <filename unknown>:0
at System.Windows.Forms.XplatUIX11.GetInstance () [0x00000] in <filename unknown>:0
at 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>:0
at 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.so
at (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>:0
at System.Windows.Forms.XplatUIX11.SetDisplay (IntPtr display_handle) [0x00000] in <filename unknown>:0
at System.Windows.Forms.XplatUIX11..ctor () [0x00000] in <filename unknown>:0
at System.Windows.Forms.XplatUIX11.GetInstance () [0x00000] in <filename unknown>:0
at 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>:0
at 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 src
nike@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.bz2
Resolving 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 OK
Length: 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$ ls
libgdiplus-2.10.9.tar.bz2 mono-3.2.8 mono-3.2.8.tar.bz2
nike@NIKE-PC:~/src$ tar -xvjf libgdiplus-2.10.9.tar.bz2
nike@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... yes
checking for BASE_DEPENDENCIES... no
configure: error: Package requirements (glib-2.0 >= 2.2.3) were not met:
No package 'glib-2.0' found
Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.

Alternatively, you may set the environment variables BASE_DEPENDENCIES_CFLAGS
and 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-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
libglib2.0-0 libglib2.0-bin libpcre3-dev libpcrecpp0 zlib1g-dev
Suggested packages:
libglib2.0-doc
The following NEW packages will be installed:
libglib2.0-dev libpcre3-dev libpcrecpp0 zlib1g-dev
The following packages will be upgraded:
libglib2.0-0 libglib2.0-bin
2 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... no
checking for png_read_info in -lpng... no
configure: 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 arguments
configure: 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-dev
nike@NIKE-PC:~/src/libgdiplus-2.10.9$ sudo apt-get install fontconfig
nike@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 the
corresponding development packages for them, rerun
autogen.sh to include them in the build.

nike@NIKE-PC:

./configure通过。

编译安装源代码

nike@NIKE-PC:~/src/libgdiplus-2.10.9$ make
make all-recursive
make[1]: Entering directory `/home/nike/src/libgdiplus-2.10.9'
Making all in pixman
make[2]: Entering directory `/home/nike/src/libgdiplus-2.10.9/pixman'
make all-recursive
make[3]: Entering directory `/home/nike/src/libgdiplus-2.10.9/pixman'
Making all in pixman
make[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=echo
nike@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 -lfontconfig
libtool: 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 line
collect2: error: ld returned 1 exit status
make[2]: *** [testgdi] Error 1
make[2]: Leaving directory `/home/nike/src/libgdiplus-2.10.9/tests'
make[1]: *** [all-recursive] Error 1
make[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/Makefile
nike@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:~$ . .bashrc
nike@NIKE-PC:~$ echo $LD_LIBRARY_PATH
/opt/mono-3.2.8/lib
nike@NIKE-PC:~$

验证libgdiplus是否安装成功

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

运行成功。

(0)

相关推荐

  • ubuntu13.10编译安装mono环境(一)

    准备工作 一个全新安装的ubuntu13.10系统 下载Mono源代码并编译 nike@NIKE-PC:~$ ls Desktop Downloads Music Public Videos Documents examples.desktop Pictures Templates nike@NIKE-PC:~$ mkdir src nike@NIKE-PC:~$ cd src nike@NIKE-PC:~/src$ wget http://download.mono-project.com/s

  • CentOS上搭建Nginx+Mono运行asp.net环境的配置方法

    安装步骤: 一.获取开源相关程序: 1.利用CentOS Linux系统自带的yum命令安装.升级所需的程序库: sudo -s LANG=C yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bz

  • linux操作系统安装MONO执行C#程序的详解步骤

    第一步 环境(UBUNTU系统下) 复制代码 代码如下: sudo apt-get install mono-gmcs mono 第二步 建立example.cs 复制代码 代码如下: class X {static void Main () {System.Console.Write("My first mono app worked!/n"):}} 第三步 编译 复制代码 代码如下: gmcs example.cs 第四步 执行 复制代码 代码如下: ./example.exe 在

  • 在CentOS 7.2下安装Mono 5.0的方法教程

    前言 微软Build2017大会期间.NET领域的.NET core之外,就是Visual Studio For Mac,大家都知道Visual Studio For Mac 是基于Mono运行的,Mono 5.0也是闪亮登场,Mono 5.0是一个非常重要的里程碑版本,支持Windows 64位部署,还有支持PowerPC等,Mono 5.0 和微软的.NET 的可操作性,兼容性也得到了更好的统一,还有很多特性为C#的游戏之王Unity准备,今年的Unity平台会有全面的升级. Mono 5.

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

    准备工作 先在VS2012上编译一个winform,代码如下: using System; using System.Windows.Forms; namespace FormsTest { static class Program { /// <summary> /// 应用程序的主入口点. /// </summary> [STAThread] static void Main() { Application.EnableVisualStyles(); Application.S

  • CentOS 6.3编译安装LAMP环境笔记

    最近抽空在虚拟机上测试成功了LAMP各个最新版本的整合编译安装,算是把之前的博文整合精简,以下内容均在CENTOS6.3(安装minimal desktop和默认开发包)下测试安装成功,并做了相应优化配置,如有遗漏,还请留言指教.   LINUX操作系统:centOS6.3 64bit(安装了系统默认开发包) APACHE:httpd-2.4.4 MYSQL:mysql-5.6.10 PHP:php-5.4.13 注:推荐安装centos6.3系统时,在系统安装向导中.将默认开发包勾上,避免后期

  • PHP7.3.10编译安装教程

    php7.3.10编译安装 配置安装环境(裸机): centos7.2 下载指定PHP版本源码包 github https://github.com/php/php-src.git download https://www.php.net/downloads.php su - root && cd ~/ wget https://www.php.net/distributions/php-7.3.10.tar.gz # 解压源码包 tar -xzvf php-7.3.10.tar.gz c

  • Centos 6.8编译安装LNMP环境(Nginx+MySQL+PHP)教程

    前言 对于新手的一点建议: 最好熟悉一下linux 的基本命令,vim的常用命令 千万不要无脑复制,先看一下命令,特别是路径要注意 学会排查错误 本篇安装的软件版本为: Linux:Centos6.8 Nginx:1.10.3 MySQL:5.7.17 PHP:7.0.16 最近研究了Linux系统下的PHP环境搭建,个人感觉最好最好不要用yum默认的程序包安装,因为版本都比较低,下载最新的稳定版自行安装比较好.现在网上教程很多,之所以还记这篇,原因有一点,当你重复网上的教程自行安装时,90%还

  • Android内核源码 在Ubuntu上下载,编译,安装

    从源代码树下载下来的最新Android源代码,是不包括内核代码的,也就是Android源代码工程默认不包含Linux Kernel代码,而是使用预先编译好的内核,也就是prebuilt/android-arm/kernel/kernel-qemu文件.那么,如何才能DIY自己的内核呢?这篇文章一一道来. 一. 首选,参照前一篇在Android源码 在Ubuntu上下载,编译和安装准备好Android源代码目录.       二. 下载Linux Kernel for Android源代码. 1.

  • CentOS6.5 编译安装lnmp环境

    网上搜来的教程如下 复制代码 代码如下: yum -y install gcc gcc-c++ automake autoconf libtool glibc make libmcrypt安装 mkdir /usr/local/source && cd /usr/local/source #创建并进入源文件目录 [root@localhost source ]# wget "http://downloads.sourceforge.net/mcrypt/libmcrypt-2.5

  • Ubuntu下nginx编译安装参数配置

    安装依赖库: sudo apt-get install libgd2-xpm sudo apt-get install libgd2-xpm-dev sudo apt-get install libgeoip-dev sudo apt-get install libpcre3 sudo apt-get install libpcre3-dev sudo apt-get install libssl-dev sudo apt-get install openssl sudo apt-get ins

  • CentOS 7.x编译安装Nginx1.10.3+MySQL5.7.16+PHP5.2 5.3 5.4 5.5 5.6 7.0 7.1多版本全能环境

    前传: 1.CentOS 7.3.1611系统安装配置图解教程 http://www.osyunwei.com/archives/10003.html 2.CentOS服务器初始化设置 http://www.osyunwei.com/archives/9034.html 准备篇 一.防火墙配置 CentOS 7.x默认使用的是firewall作为防火墙,这里改为iptables防火墙. 1.关闭firewall: systemctl stop firewalld.service #停止firew

  • CentOS 7.3.1611编译安装Nginx1.10.3+MySQL5.7.16+PHP7.1.2

    前传: 1.CentOS 7.3.1611系统安装配置图解教程 http://www.jb51.net/os/RedHat/597874.html 2.CentOS服务器初始化设置 http://www.jb51.net/article/133839.htm 准备篇 一.防火墙配置 CentOS 7.x默认使用的是firewall作为防火墙,这里改为iptables防火墙. 1.关闭firewall: systemctl stop firewalld.service #停止firewall sy

随机推荐