views:

231

answers:

5

In what measure is developing with mono cross-platform? How do I compile for Windows (in Linux), how do I run things in Linux (because there is no .NET JIT compiler)?

So what are the particularities of developing with Mono? What are the advantages over developing with Visual Studio (except cross-platform thinghie)?

A: 

If you want to get started with real cross platform, it pains me to say it (because it's C++, not because I like C#), you should start with these links:

Matt Joiner
While your answer might be right, it's no-way related to the OP's question.
Alan
I find that writing platform independent C++ is actually really, really hard. I like C++, but it takes some wicked kung foo precompiler magic to write code in C++ that will run in *nix and Windows and OSX and...
kbrimington
@kbrimington: If you're relying on precompiler magic, you're probably not using the right libraries (they should do the kung fu for you).
Mark
@kbrimington: honestly it's not hard **if** you're using gcc/g++ as it's `-wall` is amazingly good at finding potential gotchas. VC++2010 has gotten much better, but it's still behind g++ interms of adhering to the standard.
Alan
@Mark: Touche. I'll give you that. @Alan: Thanks for the heads up.
kbrimington
Of course I consider C++ for real cross-platform development, but I was reffering strictly to .NET and Mono.
Andrei
Good that you qualify it as "real" cross platform. Why not just call C++ real and stick to it? :)
Matt Joiner
I want to learn a little bit of .Net and mono, just so I won't die a stupid ignorant. After that, I'll continue my c++ journey.
Andrei
@Andrei: If that is your intention, proceed directly to C. Do not pass Java/C#, do not collect an interpreter.
Matt Joiner
+1  A: 

The only advantage developing on Mono is that you can use a Mac OS X or Linux environment. But if you have a choice, never leave Visual Studio. To the best of my knowledge, Visual Studio is the best IDE available for development in C# and VB.

BennySkogberg
That's not true at all. If you develop with Visual Studio, you can use Mono to run your executable on mac and linux (provided your exe uses .Net libraries that are supported by mono).
Alan
'It is the best IDE available'... I hope you don't want to start a flamewar.
dkson
@dkson I never want to start a war of any kind. Sentence changed. Thanx!
BennySkogberg
As long as C# is Microsoft's, and Visual Studio is the only official tool for .Net and C#, I think @BennySkogberg is right.
Andrei
@Andrei: Actually that's not true. Microsoft also has CSC, the C# commandline compiler, which comes with the .NET Framework, and does not need Visual Studio installed to use. Even MSFT mentions Mono as a tool: http://msdn.microsoft.com/en-us/library/ms379563%28VS.80%29.aspx
Alan
+10  A: 

Developing in Mono is definitely cross-platform with a caveat emptor:

  • Strive to steer clear of Windows specific API's
  • No interoperability with the native Windows API's... or... you can #ifdef out the Windows API and provide your own Mono wrapper in order to minimize code changes, for example, there's a DLL wrapper that uses Interop to invoke a Win32 method such as 'GetFont', this is a hypothetical example, GetFont will return the Font information, under Mono, that does not exist but however you can create a fake wrapper that returns nothing and incorporate the #ifdef macro to use the wrapper when compiling under Mono, and switch off the macro when compiling under Windows, how you implement the wrapper is up to you.
  • Do not use advanced GUI properties that may not be present in Mono.
  • Use the Environment property such as NewLine to make it independant of Unix's CR and Win32's CRLF, same apply for Path Separator, for Unix '/' and for Win32 '\'.
  • Serialization is slightly different under Mono, you serialize an object on Mono, do not kid yourself into thinking it will be de-serialized under Win32 and vice versa.

Lastly but not least, keep checking from Mono to Win32 and back again, keep testing and testing it.

tommieb75
Thank you a lot for the info.
Andrei
@Andrei: you're welcome! :)
tommieb75
+1  A: 

Much of the mono runtime is compatible with the CLR, as they follow the same standard.

This means that once you compile your code (in Mono or visual studio), so long as you make sure to only use features supported by both (for example no WMI stuff in mono) and write your application to be platform aware, using best practices (examples are using Path.Combine to build file and directory paths, using Environment.NewLine for outputting new lines and more), your application can run unmodified on any platform that has either Mono or the CLR (this includes Windows, Linux and Mac).

You can develop with mono in visual studio, so the part of your question regarding that is moot.

Oded
So if I compile with Mono, I can also run with .NET, or I still need Mono installed on windows?
Andrei
Again, so long as you keep to features that both runtimes have, the answer is that you do not have to install mono in order to run it on windows.
Oded
+1  A: 

Mono itself is cross platform.

By developing with mono specifically, you will be able to run your executable on any platform that has mono available for it. That in and of itself is mono's biggest advantage over developing on MSFT's .Net platform. Said differently: If you build you assembly with mono, you're guarantee cross-platform support, where as building with .Net may not give you that.

Mono has made some upgrades to deficiencies in .Net (for example Mono.security offered features not found in .Net 2.0, though I believe MSFT picked them up for later releases).

It is possible to build a .Net Assembly using Visual Studio, and have Mono run it on, however your assembly must take care to use only the frameworks/libraries that Mono supports, and that any unmanaged assemblies referenced by your assembly are available for your chosen OS. In otherwords: if your assembly makes use of a C++ dll on windows, you must ensure you have the correct .a/.so file for linux.

To run your .net assembly in Linux (assuming mono is installed properly) you type: mono myprogram.exe

Alan
So if I compile with Mono, I can also run with .NET, or I still need Mono installed on windows?
Andrei
If you compile with mono, and your assembly uses specific mono libraries that aren't part of the standard .NET framework, then yes you will need Mono installed.
Alan
Is the system library considered cross-plaform?
Andrei
No .Net libraries are cross platform. I think question you want to ask is "Is the system library implemented in mono?" The answer is yes. System is fully supported.
Alan
Yes, that was my question
Andrei