服务器之家:专注于服务器技术及软件下载分享
分类导航

Linux|Centos|Ubuntu|系统进程|Fedora|注册表|Bios|Solaris|Windows7|Windows10|Windows11|

服务器之家 - 服务器系统 - Ubuntu - ubuntu 13.10编译安装mono环境(二)

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

2021-10-18 17:41ubuntu教程网 Ubuntu

接上篇,上篇仅安装了Mono本身,并没有安装libgdiplus、gtk-sharp、mod_mono、MonoDevelop 等其他相关的软件。 这篇主要是配置安装libgdiplus。

准备工作

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

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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运行:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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并编译

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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 &gt;= 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:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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安装配置文件:

?
1
2
3
4
5
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:

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

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

?
1
2
3
4
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:

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

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

?
1
2
3
4
5
6
7
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:

?
1
2
3
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安装配置文件:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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通过。

编译安装源代码

?
1
2
3
4
5
6
7
8
9
10
11
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即可:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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即可

?
1
2
3
4
5
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环境变量

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

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

?
1
2
3
4
nike@NIKE-PC:~$ . .bashrc
nike@NIKE-PC:~$ echo $LD_LIBRARY_PATH
/opt/mono-3.2.8/lib
nike@NIKE-PC:~$

验证libgdiplus是否安装成功

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


运行成功。

延伸 · 阅读

精彩推荐
  • UbuntuUbuntu上搭建git server笔记

    Ubuntu上搭建git server笔记

    这篇文章主要介绍了Ubuntu上搭建git server笔记,本文讲解了安装配置git服务器、安装配置gitosis、在服务器上新建一个测试项目仓库、管理gitosis的配置文件等步...

    Ubuntu教程网5292019-10-17
  • UbuntuUbuntu上FTP服务器程序vsftpd安装配置全流程攻略

    Ubuntu上FTP服务器程序vsftpd安装配置全流程攻略

    vsftpd是服务器端最最常用的FTP服务架设程序,这里我们就从部署和用户访问控制等多个基础方面,来看一下Ubuntu上FTP服务器程序vsftpd安装配置全流程攻略:...

    Ubuntu之家6512019-06-04
  • Ubuntu安装ubuntu12.04后无线网卡驱动安装方法分享

    安装ubuntu12.04后无线网卡驱动安装方法分享

    安装ubuntu 12.04后,无线网卡不可用,采用以下方式解决,大家参考使用吧 ...

    ubuntu教程网6132019-11-07
  • UbuntuUbuntu系统怎么用git新增分支并且提交?

    Ubuntu系统怎么用git新增分支并且提交?

    Ubuntu系统怎么用git新增分支并且提交?Ubuntu中想要使用git新增分支并且提交,该怎么常见一个新的分支呢?下面我们就来看看详细的教程,需要的朋友可以...

    燃烧的猛男14752020-06-05
  • UbuntuUbuntu中使用NTP实现时间同步的方法

    Ubuntu中使用NTP实现时间同步的方法

    这篇文章主要介绍了Ubuntu中使用NTP实现时间同步的方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可...

    陌鉎こ城sHi5482020-09-11
  • Ubuntudebian7更换gcc版本的二种方法分享

    debian7更换gcc版本的二种方法分享

    最近在编译qt,之前用的是debian6,gcc版本是gcc-4.4,当使用debian7时,编译遇到了很多跟debian6不一样的问题,debian7的默认gcc使用的是gcc-4.7,可能是编译器版...

    debian教程网2262019-11-18
  • UbuntuUbuntu下安装Docker教程

    Ubuntu下安装Docker教程

    Docker是一个开源软件,它可以把一个Linux应用和它所依赖的一切(比如配置文件)都封装到一个容器。然而,Docker与虚拟机不同,它使用了沙箱机制,Dock...

    阿_毅3042020-11-30
  • UbuntuUbuntu20.04安装搜狗输入法的详细步骤

    Ubuntu20.04安装搜狗输入法的详细步骤

    这篇文章主要介绍了Ubuntu20.04安装搜狗输入法的方法,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友...

    風の住む街~15892020-07-20