1

Is it possible to bundle a Mono executable using mkbundle that uses the sgen GC?

I assume that because the produced bundle requires the libmono-2.0.so.1 instead of the libmonosgen-2.0.so that it is using the standard boehm GC. I have tried using $MONO_OPTIONS=--gc=sgen but the resulting bundle still requires the non-sgen lib.

Am I misunderstanding the use of the libmono and libmonsgen libs?

Thank you for any assistance or guidance

drg
  • 83
  • 1
  • 10

2 Answers2

1

This is a bit tricky, because Mono actually has two separate executables and two separate libraries, one for each garbage collector. For example, if you run mono --gc=sgen ... then mono will actually do an execvp() of mono-sgen ... to switch to a different executable.

Similarly, mkbundle will use pkg-config to select the library and link one or the other (i.e. whichever is the system default). To get the other library, there are two options:

One is to rebuild Mono with sgen being the default. Obviously, that may not be a viable solution.

The alternative is to use pkg-config to override the selection. You'd create a copy of mono-2.pc, replace -lmono-2.0 with -lmonosgen-2.0, update prefix and exec_prefix and use the PKG_CONFIG_PATH environment variable to pick that version.

Note that I've never actually tried the latter, but there is no reason why it shouldn't work, since pkg-config is where mkbundle gets the library path from.

Reimer Behrends
  • 8,600
  • 15
  • 19
  • Thank you for the response. You helped me understand that the mono-2.pc is the file that specifies what to link to create the executable. Interestingly, there is already a monosgen-2.pc file located in the lib/pkgconfig directory. This makes me think that there must be a way to override the use of mono-2.pc using a command line switch or an environment variable. I tried changing the PKG_CONFIG_PATH to actually include the file but it was not successful. – drg Jun 28 '13 at 13:20
  • If you look at the `mkbundle.cs` source, you'll see that `mono-2.pc` is hardcoded, unfortunately. However, after testing it right now, it worked for me in that the program I tested was linked against libmonosgen-2.0.0.dylib (on a Mac, using Mono 3.0.10) and it ran successfully. Note that `PKG_CONFIG_PATH` has to point to the directory containing the file, not the file itself. – Reimer Behrends Jun 28 '13 at 17:22
  • In your above answer, you say "One is to rebuild with sgen being the default"...Does that mean rebuild mono itself or rebuild the application. I am guessing you mean rebuild mono itself as I cannot seem to find any info on how to specifiy it to mcs. Thank you for your insight regarding looking at the code. Sadly, coming from a heavy MS and Visual Studio background...that did not even occur to me. It should have :). – drg Jun 28 '13 at 20:44
  • Yes, I meant rebuilding Mono, which may just be a bit extreme for this. :) – Reimer Behrends Jun 28 '13 at 20:54
0

Thanks for this question as it helps me to determine why one of my applications is running too slowly after bundling with the mkbundle. It was because of the Boehm GC engine being used.

To include SGen you just need to invoke mkbundle with --keeptemp flag and then rewrite compiler command (which is printed by mkbundle) to include monosgen-2 instead of mono-2.

Example: (for Mac, but could be easily rewritten for Linux)

export PATH=/Library/Frameworks/Mono.framework/Commands/:$PATH
export AS="as -arch i386"
export CC="cc -arch i386 -framework CoreFoundation -lobjc -liconv"

mkbundle TestApp.exe --deps --static -o TestAppBundleName --keeptemp

cc -arch i386 -framework CoreFoundation -lobjc -liconv -o TestAppBundleName -Wall `pkg-config --cflags monosgen-2` temp.c  `pkg-config --libs-only-L monosgen-2` `pkg-config --variable=libdir monosgen-2`/libmonosgen-2.0.a `pkg-config --libs-only-l monosgen-2 | sed -e "s/\-lmonosgen-2.0 //"` temp.o
ai_enabled
  • 71
  • 5