Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best practices for .NET/MONO cross compiling

Tags:

.net

mono

What are the best practices for writing code that can be cross compiled on .NET (windows) and Mono (linux)? Although I am very familiar with .NET, I am not that experienced in Mono and all its gotchas. Has anyone seen a good blog post or best practices paper on this, which I have not been able to dig up? I would be sticking with C# 3.0 level features.

Things that concern me is first of all Interop, since I would need to call some native code. Next would be the best ways to handle namespaces such as Mono.XXX. Should I be using a bunch of #if? Isolate the code in per-platform assemblies?

Any suggestions regarding architecture and design would be greatly appreciated! If you have had any experience in cross compiling for Linux/Mono in visual studio (any version), I would also be interested in that.

like image 431
Will I Am Avatar asked Nov 24 '09 21:11

Will I Am


People also ask

Why is cross compiling so hard?

"building a cross-compiler is significantly harder than building a compiler that targets the platform it runs on." The problem exists due to the way libraries are built and accessed. In the normal situation all the libraries are located in a specific spot, and are used by all apps on that system.

Which software is used for cross compilation?

GCC, a free software collection of compilers, can be set up to cross compile. It supports many platforms and languages. Cross-compiling GCC requires that a portion of the target platform's C standard library be available on the host platform.


2 Answers

The biggest issues are sticking to the Mono-supported APIs. Using the Visual Studio Integration support in Mono can help a lot with this, since you can target Mono the entire time, on all platforms.

For your specific questions:

1) Interop - You'll need to stick to P/Invoke. Try to isolate this into separate, platform specific assemblies. This leads to 2:

2) Using #if - I would avoid this, and prefer to use an extensibility model. Mono supports the Managed Extensibility Framework, which provides a good way to "plug in" platform specific code at runtime.

like image 90
Reed Copsey Avatar answered Oct 15 '22 11:10

Reed Copsey


You should be interrested by Prebuild :

Prebuild is a cross-platform XML-driven pre-build tool which allows developers to easily generate project files for major IDE's and .NET development tools including: Visual Studio .NET 2002, 2003, 2005, SharpDevelop, MonoDevelop, NAnt and Autotools.

like image 28
Larry Avatar answered Oct 15 '22 11:10

Larry