3

I have created a simple console window app within Xamarin Studio for mac.os. I hit debug and I see the console app. All works ok.

But if I open a bash shell and navigate to the bin/Debug location and try to run the program, I get the message: 'cannot execute binary file'.

I suspect that there are some libs that aren't being linked. Maybe when I run within Xamarin, it is setting up the environment to run/debug the app. I do not see any build options within Xamarin Studio for linking.

I am a newbie to Xamarin and have a 'real' console app that I would like to link and distribute. Any pointers would be helpful thanks.

Thanks, bruce

brewsky
  • 607
  • 1
  • 9
  • 15
  • You're trying to execute a .net executable directly, if you want it to work as an standalone app you must create a Bundle, look at the Xamarin docs on how to do it. – Gusman Jan 05 '16 at 14:31

2 Answers2

3

The output .exe file is a .NET executable, when it is run through the debugger it is launched and executed by the mono executable.

You can run the .exe by navigating to it via terminal and running:

mono MyConsoleApp.exe

This will run the console apps .exe using the mono vm.

If you want to bundle the .exe, you need to use mkbundle.

This is the sequence of shell commands I've used to generate an OSX executable using mkbundle:

# Configure pkg config path.
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/lib/pkgconfig:/Library/Frameworks/Mono.framework/Versions/3.0.12/lib/pkgconfig

# Configure Mono.Framework path.
export PATH=/Library/Frameworks/Mono.framework/Commands:$PATH

# Setup the architecture and framework references
export AS="as -arch i386"
export CC="clang -framework CoreFoundation -lobjc -liconv -arch i386 -mmacosx-version-min=10.6"

# Bundle the app. --deps auto-magically includes all dependencies for the .net exe, -o specifies the output native executable filename.
mkbundle MyConsoleApp.exe --deps -o MyConsoleApp

This will generate an executable for OSX named MyConsoleApp (the native executable) for MyConsoleApp.exe (the .NET executable) named that you can double click to run.

matthewrdev
  • 11,930
  • 5
  • 52
  • 64
  • Thanks for the reply. I built as suggested and sent the output to another developer to test/install/execute. There are 2 issues from this test. 1) When he runs he gets a 'monoboehm.dylib not found' runtime error. I researched and I apparently have to use '--static' on the mkbundle command. 2) Since using the 'mmacosx-version' flag, mkbundle now complains that 'object file was build for new OSX version (10.11) then being linked. I don't see an option in Xamarin Studio to set the OSX version. Is that taken care of by the CC env var? – brewsky Jan 07 '16 at 16:59
0

Just to note the other answer referencing mkbundle is only applicable to MonoMac. Xamarin.Mac applications now generate a native launcher application to handle this for you.

Chris Hamons
  • 1,510
  • 11
  • 22