[Mono-winforms-list] basic assistance

Jon Heiner jon.heiner@gmail.com
Sat, 9 Apr 2005 20:51:54 -0700


I was able to get my Mac MWF app running. Thanks for the help. I found  
out that there is a wrong
way and a right way to get things working. As Karma for the assistance  
I received, I am jotting
down my steps for getting things to work so newcommers don't hit these  
problems. For the
existing developers I hope this is useful to see what mistakes  
newcomers make.

Basically, it's simple to get things up and running if you do it the  
right way, but the wrong way
makes for incredible pain and crazy dependencies that you don't  
actually need.

heina

First off, the right way.
0. My System: Mac Powerbook G4 OSX 10.3.8
1. write your app (mine's in csharp, code is below)
2. use mono1.1.5 as 1.1.6 appears to have a bug. get it from  
http://www.mono-project.com/OldReleases
3. compile your code with mcs and pack with macpack (makefile is below)
4. go to the Finder and double click the app there to launch
5. if you need to see debug output, launch the console from the Finder  
/Applications/Utilities/Console
________________________________________________________________________ 
__________
Makefile:
all: clean helloworld
clean:
         rm helloworld.exe
         rm -Rf helloworld.app
helloworld:
         mcs -r:System.Windows.Forms -r:System.Drawing helloworld.cs
         macpack -m:1 -n:helloworld -o:. -a:helloworld.exe
________________________________________________________________________ 
__________
HelloWorld.cs (sample code for newcomers)

using System;
using System.Windows.Forms;

public class HandDrawnClass : Form
{
         public static void Main()
         {
                 Application.Run( new HandDrawnClass() );
         }

         public HandDrawnClass()
         {
                 _output          = new System.Windows.Forms.Label();
                 _output.Location = new System.Drawing.Point( 16, 24 );
                 _output.Text     = "Hello, World!";
                 _output.Size     = new System.Drawing.Size( 216, 24 );

                 _cancel          = new System.Windows.Forms.Button();
                 _cancel.Location = new System.Drawing.Point( 150, 200 );
                 _cancel.Text     = "&Close";
                 _cancel.Size     = new System.Drawing.Size( 112, 32 );
                 _cancel.Click   += new System.EventHandler(  
this.OnClick );

                 this.Text        = "Hello, World!";
                 this.AutoScaleBaseSize = new System.Drawing.Size( 5, 13  
);
                 this.ClientSize  = new System.Drawing.Size( 300, 300 );
                 this.Controls.Add( _output );
                 this.Controls.Add( _cancel );
         }

         private void OnClick( object sender, System.EventArgs e )
         {
                 Application.Exit();
         }

         private System.Windows.Forms.Label  _output;
         private System.Windows.Forms.Button _cancel;
}
________________________________________________________________________ 
__________
BELOW HERE IS THE WRONG WAY. FOR REFERENCE ONLY
Here is the WRONG way to do this. these are my notes the first time.
These were the hoops I jumped through before I found out how easy it  
was.
Btw, the steps below DO work for getting the app up and running. :(
Unfortunately, most of this is not necessary.

1. you need X11 (to my knowledge).
  - you can run it from Applications/Utilities/X11
  - an X server must be running before you can start a MWF app
  - your DISPLAY variable might not be set.
  - you can set it in bash with the command:     export DISPLAY=:0.0
  - if you don't have X, you can get it from  
http://www.apple.com/macosx/features/x11/

2. get mono setup
  - as of mono 1.1.6 (likely fixed in the future), there is a bug.
  - get mono 1.1.5.
  - you can get it off the mono downloads site, but you'll need to poke  
around in Old Versions in Development Branch
  - i found it here: http://www.mono-project.com/OldReleases
  - grab the .dmg (disk image), download it, mount it, and install
  - it installs to /Libraries/Frameworks/Mono.framework/Versions/1.1.5
  - check that it's setup by doing:   which mono; which macpack; which  
mcs

3. you'll need libgdiplus.dylib in your path
  - this is installed in  
/Libraries/Frameworks/Mono.framework/Versions/1.1.5/lib/ 
libgdiplus.dylib
  - it's a symlink (on my install) libgdiplus.0.0.0.dylib
  - setup your dynamic library search path to include this directory
  - the command for bash is: export  
DYLD_LIBRARY_PATH=/Library/Frameworks/Mono.framework/Versions/Current/ 
lib

4. building and running
  - building requires two passes, one that uses mcs to create an exe and  
another which uses macpack to build an app
  - to run from the command line is a bit tricky as well. i've put my  
scripts in this file.
  - however, if everything has gone ok, you can double click the app  
that is created from the Finder and your app should run
  - the output from the app should go to  
helloworld.app/Contents/Resources/helloworld.exe
  - you can run the exe with the script


file: run   (chmod +x run)
	export  
DYLD_LIBRARY_PATH=/Library/Frameworks/Mono.framework/Versions/Current/ 
lib
	pushd ~/projects/wwarlock/helloworld/helloworld.app/Contents/Resources
	mono helloworld.exe
	popd

ABOVE HERE IS THE WRONG WAY. FOR REFERENCE ONLY
________________________________________________________________________ 
__________


On Apr 9, 2005, at 1:05 PM, Peter Dennis Bartok wrote:

You cannot use mono <executable> to run SWF apps on the mac. You need  
to run
what macpack generates.

Peter

-----Original Message-----
From: "Jon Heiner" <jon.heiner@gmail.com>
To: <mono-winforms-list@lists.ximian.com>
Date: 09 April, 2005 13:08
Subject: [Mono-winforms-list] basic assistance


> [apologies if this is a repost]
>
> I'm trying to get an extremely simple Windows.Forms app running. I'm
> assuming it's one of a.) bad install, b.) conflicts between versions,
> c.) incorrect command line, or d.) incorrect calling context. I've
> attached all the relevant documentation. I'm sure i'm doing something
> boneheaded. fyi, the code compiles fine and the macpack generates an
> app. build code below. i just can't run it.
>
> My overall goal, btw, is to get a simple window up, grab the GD and
> draw my own stuff straight to there. But i've been trying for a few
> days to get this working to no avail. but I know you guys are doing it
> successfully since I see ongoing controls development.
>
> thx in advance. heina
>
>
> system:
> OSX 10.3.8 Powerbook G4
> both mono 1.1.4 & 1.1.6 installed (this may be causing conflicts. 1.1.6
> is active, but when i installed X from apple.com it put the dylibs in
> 1.1.4 only)
> running mono from an actual xterm instead of the mac terminal (is this
> necessary?)
>
> stacktrace:
> $ /Library/Frameworks/Mono.framework/Versions/1.1.4/bin/mono
> helloworld.exe
>
> Unhandled Exception: System.TypeInitializationException: An exception
> was thrown by the type initializer for System.Drawing.GDIPlus --->
> System.DLLNotfoundException:
> /Library/Frameworks/Mono.framework/Version/1.1.4/lib/libdgiplus.dylib
> in <0x000d8> (wrapper-to-native) System.Drawing.GDIPlus:GdiplusStartup
> (
> .....
>  in System.Windows.Forms.XplatUI:get_DefaultClassName()
>
> and yes, the dylib is actual resident there?!?!
>
> make commands:
> mcs -r:System.Windows.Forms -rSystem.Drawing helloworld.cs
> macpack -m:1 -n:helloworld -o:. -a:helloworld.exe
>
> code:
> using System;
> using System.Windows.Forms;
>
> public class HelloWorld : Form
> {
>         public static void Main()
>         {
>                 Application.Run( new HelloWorld() );
>         }
>
>         public HelloWorld()
>         {
>                 this.Text        = "Hello, World!";
>                 this.AutoScaleBaseSize = new System.Drawing.Size( 5, 13
> );
>                 this.ClientSize  = new System.Drawing.Size( 300, 300 );
>
>                 _output          = new System.Windows.Forms.Label();
>                 _output.Location = new System.Drawing.Point( 16, 24 );
>                 _output.Text     = "Hello, World!";
>                 _output.Size     = new System.Drawing.Size( 216, 24 );
>
>                 _cancel          = new System.Windows.Forms.Button();
>                 _cancel.Location = new System.Drawing.Point( 150, 200  
> );
>                 _cancel.Text     = "&Close";
>                 _cancel.Size     = new System.Drawing.Size( 112, 32 );
>                 _cancel.Click   += new System.EventHandler(
> this.OnClick );
>         }
>
>         private void OnClick( object sender, System.EventArgs e )
>         {
>                 Application.Exit();
>         }
>
>         private System.Windows.Forms.Label  _output;
>         private System.Windows.Forms.Button _cancel;
> }