Preparatory work
First compile a WinForm on the VS2012, the following code:
Using System;
Using System.Windows.Forms;
Namespace Formstest
{
static class
program {
///<summary>
///application's main entry point.
///</summary>
[STAThread]
static void Main ()
{
application.enablevisualstyles ();
Application.setcompatibletextrenderingdefault (false);
Application.Run (New Form ());}}
Try running with mono on Ubuntu:
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 is thrown by the type initializer for System.window S.forms.xplatui---> System.TypeInitializationException:An exception is thrown by the type initializer for System.dra Wing. 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.Fro Mhdcinternal (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.Applic ation. EnableVisualStyles () [0x00000] in <filename unknown>:0 at FormsTest.Program.Main () [0x00000] in <filename unkno
wn>:0 [ERROR] FATAL unhandled EXCEPTION:System.TypeInitializationException:An EXCEPTION is thrown by the type initializer for System. Windows.Forms.XplatUI---> System.TypeInitializationException:An exception is thrown by the type initializer for Syst Em. 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 Syst Em. 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 <filena Me unknown>:0 at System.Windows.Forms.XplatUI. Cctor () [0x00000] in <filename unknown>:0---End of inner exception stack trace---at System.Windows.Forms.Applic ation. EnableVisualStyles () [0x00000] in <filename unknown>:0 at FormsTest.Program.Main () [0x00000] in <filename unkno
wn>:0
Encountered an error system.dllnotfoundexception:/opt/mono-3.2.8/lib/libgdiplus.so, because if you want to run WinForm in Ubuntu, you must install Libgdiplus.
Download Libgdiplus and compile
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 ... 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 [20743 17/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 = =============> omitted a lot of <============== checking pkg-config are 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 PA Ckage ' glib-2.0 ' found consider adjusting the PKG_CONFIG_PATH environment variable if you installed software in a Non-stan
Dard prefix. Alternatively, you could set the environment variables base_dependencies_cflags and base_dependencies_libs to avoid the need
To call Pkg-config.
The Pkg-config man page is for more details.
Encountered an error, you need to install Libglib2.0-dev:
nike@nike-pc:~/src/libgdiplus-2.10.9$ sudo apt-get install libglib2.0-dev
Reading Package ... Done
Building Dependency the
Reading state information ... Done the
following extra packages would be installed: libglib2.0-0 libglib2.0-bin libpcre3-dev libpcrecpp0
Zlib1g-dev
suggested Packages:
Libglib2.0-doc the
following NEW packages would be installed:
Libglib2.0-dev Libpcre3-dev libpcrecpp0 Zlib1g-dev The following packages would 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 would be used.
Do your want to continue [y/n]?
==============> omitted a lot of <==============.
To reinitialize the Libgdiplus installation configuration file:
nike@nike-pc:~/src/libgdiplus-2.10.9$/configure--prefix=/opt/mono-3.2.8
==============> omitted a lot of <====== ========
checking for libpng14 ... checking for libpng12 ... no
checking for png_read_info in-lpng ... no
confi Gure:error: * * * libpng12 not found. Http://www.libpng.org/pub/png/libpng.html.
Also encountered error, need to install Libpng-dev:
nike@nike-pc:~/src/libgdiplus-2.10.9$ sudo apt-get install Libpng-dev
To reinitialize the Libgdiplus installation configuration file:
nike@nike-pc:~/src/libgdiplus-2.10.9$/configure--prefix=/opt/mono-3.2.8
==============> omitted a lot of <====== ========
./configure:line 13371:test:too Many arguments configure:error
: "Failed to compile with x11/xlib.h Include. You must fix your compiler paths "
Prompt for error, need to install Libx11-dev:
nike@nike-pc:~/src/libgdiplus-2.10.9$ sudo apt-get install Libx11-dev
To reinitialize the Libgdiplus installation configuration file:
nike@nike-pc:~/src/libgdiplus-2.10.9$/configure--prefix=/opt/mono-3.2.8
==============> omitted a lot of <====== ========
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
Need to install FreeType and 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
To reinitialize the Libgdiplus installation configuration file:
nike@nike-pc:~/src/libgdiplus-2.10.9$/configure--prefix=/opt/mono-3.2.8
==============> omitted a lot of <====== ========
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/) c9/>-Jpeg:no (Get it from Http://freshmeat.net/projects/libjpeg)
-Gif:no (on http://sourceforge.net/projects/ Libgif)
-Png:yes note:if any of the
above say ' no ' and may install the corresponding development
s for them, rerun
autogen.sh to include them in the build.
NIKE@NIKE-PC:
./configure passed.
Compiling the installation source code
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
There was an error, Google search, probably because the $echo variable was defined in the Libtool script that was generated in the project directory, but in the script file ltmain.sh, the $echo (the generated libtool version is too old) is simple to use. Echo=echo can be:
nike@nike-pc:~/src/libgdiplus-2.10.9$ export Echo=echo nike@nike-pc:~/src/ libgdiplus-2.10.9$ make ==============> omitted a lot of <============== 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 ... /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 comma nd line Collect2:error:ld returned 1 exit status Make[2]: * * * [Testgdi] Error 1 Make[2]: Leaving directory '/home/nike/s Rc/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
Compile error again, the solution is: 1. After running./configure, edit Tests/makefile file 2. In makefile file 130 line position, change libs =-lpthread-lfontconfig to libs =- Lpthread-lfontconfig-lglib-2.0-lx11 3. Run make again
nike@nike-pc:~/src/libgdiplus-2.10.9$ vim tests/makefile
nike@nike-pc:~/src/libgdiplus-2.10.9$ make
===== =========> compiles quickly <==============
nike@nike-pc:~/src/libgdiplus-2.10.9$ sudo make install
============= => omitted a lot of <==============.
Installation complete.
Set PATH environment variable
nike@nike-pc:~/src/mono-3.2.8$ CD ~
nike@nike-pc:~$ vim. BASHRC
Append the following statement at the end of the file: Export Ld_library_path=/opt/mono-3.2.8/lib then:
nike@nike-pc:~$. . BASHRC
nike@nike-pc:~$ echo $LD _library_path
/opt/mono-3.2.8/lib
nike@nike-pc:~$
Verify Libgdiplus is installed successfully
nike@nike-pc:~$ CD desktop/
nike@nike-pc:~/desktop$ Mono FormsTest.exe
Run successfully.