Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

How to port the OpenMI environment from Windows to Linux

Table of contents

Table of Contents

1. Introduction

The document describes how to generate and run Linux dlls and executables from the original Windows C# sources. This is done by using Mono, a .NET Open Source project on different platforms. Only few adjustments are necessary in order to port the complete OpenMI functionality:

  • the standard OpenMI.Standard
  • the source development kit Oatc.OpenMI.Sdk.*
  • the dlls and executables Oatc.OpenMI.Gui.* for running OpenMI in the configuration editor with GUIs or from command line.

2. Technical prerequisites

2.1. Machine and OS of the test system

  • workstation with an Intel Xeon processor
  • 64bit openSUSE 11.0

    2.2. Mono

  • Mono v. 1.9.1. for openSUSE 11.0 in 64 bit mode. V. 1.9.1. is also referred to as Mono 2.0.
  • The standard and the sdk sources should be compilable with previous versions. But the GUIs require Windows.Forms, which has been shipped with v. 1.9.1. in Oct. 2009.

3. How to compile and execute a Mono application

3.1. Commands

Command for generating a dll:

...

Panel
bgColor#F7D6C1
borderStyledashed

gmcs -out:<target>.exe -r<linkedLib_1>.dll,<linkedLib_k>.dll -pkg:<package_1>.pc;...;<package_m>.pc <source_1>.cs <source_n>.cs

3.2. Mono and Grapical User Interfaces GUIs

The GUI sources use Windows.Forms, that works with resource files in order to design the graphical elements. The Windows resource files (*.resx) are generated automatically in the Microsoft Visual Studio IDE. Linux applications do not process them and create a "resource not found" exception during runtime. Thus, the resources have to be converted with the Mono tool resgen / resgen2. The following command generates a Linux readable resource <name>.resource:
resgen <name>.resx generates a Linux readable resource <name>.resource .
Visual Studio assigns a resource file to a C# file automatically. On a Linux machine naming conventions guarantee the correct assignment. On linux systems C# and resource file must have the same prefix. This first part of the prefix must be the namespace.

...

Mono can not process all type of GUIs. Mono 2.0 has nearly the full functionality of Windows.Forms. It does not support the WindowsPresentationFoundation WPF, shipped since .NET 3.0, which generates resources in XAML style or logical resources. Thus, it is highly recommended to use Forms elements in OpenMI GUIs instead of WPF elements.

3.3. Help for Developers

Mono Forums are very helpful: http://www.go-mono.com/forums/
A part of the error messages are the same as in Microsoft Windows .NET. You look them up on the MSDN homepage.

4. OpenMI on Mono in five steps

4.1. Download from SourceForge


Fig. 1: Directory structure

...

4.2. Building with shell scripts

  • Go to $OPENMI_DIR/Oatc/src/csharp/Linux/
    Edit the package files *.pc:
  • drawing.pc: replace the path for System.Drawing.dll
  • nunit-framework.pc: replace the path for nunit.framework.dll
  • windows-forms.pc: replace the path for System.Windows.Forms.dll
  • Run build.Standard.sh
  • Run build.Sdk.sh and the Sdk including UnitTest will be built.
  • Run build.Gui.sh and the Gui including UnitTest will be built.
  • Run build.Examples.ModelComponents.SpatialModels.sh will generate test models.
    All dlls and exe files will be copied to $OPENMI_DIR/Oatc/src/csharp/bin/.

4.3. Running the applications

Mono applications do not run directly on the Linux system, they are interpreted in a runtime engine, comparable to the virtual machine in java. Thus, the command in the terminal window command line has to start with mono:
mono Oatc.OpenMI.Gui.ConfigurationEditor.exe
mono Oatc.OpenMI.Gui.ConfigurationEditor.exe

4.4. UnitTests

  • Go to $OPENMI_DIR/Oatc/src/csharp/Linux/
  • runNunit.Sdk.sh for all Sdk dlls
  • runNunit.Gui.sh for Oatc.OpenMI.Gui.Core.dll
  • runNunit.Examples.ModelComponents.SpatialModels.sh e.g. for a RiverModel and a GroundWaterModel

4.5. Can I use the same sources for Linux and Windows

Yes, you can generate a set of dlls and exe files for Linux and a set for Windows with the same sources. The method Gui/Core/Utils.IsRunningOnMono decides during runtime, whether it runs on Mono or not. The build.*.sh scripts are tailored for Linux, for Windows you can use the Visual Studio projects.

4.6. Buildung the OpenMI with MonoDevelop

The IDE MonoDevelop is an alternative to the scripts, s. 4.2. It import Microsoft projects by loading the *.sln file. The author had some compilation problems with MonoDevelop 2.0 Alpha without clear error messages. Experienced developers may find a solution. Furthermore, MonoDevelop will be constantly improved in 2009, s. http://www.mono-project.com/Roadmap

5. Miscellaneous

5.1. Running on non-SUSE Linux?

The generated applications will probably run on further platforms, especially non-SUSE Linux derivates, without re-compilation. But it has not been proved yet. Interested persons are invited to try. A short notice to the community, e.g. to the OpenMI Forum on SourceForge would be great.

5.2. Todo list

  • portation of the OpenMI Tools
  • portation of the SimpleRiver example

...