[Mono-dev] Embedding Mono: multiple calls to mono_jit_init

MartinAlexander martin.arvidsson at gmail.com
Fri May 20 04:18:26 EDT 2011

Hello I've tried the dynamic loading of mono and I havn't had any success.

I've written an example to test it out, this example is tested on Ubuntu
10.04 (with GCC 4.3, Mono 2.6.7), Debian 6 (with GCC 4.4, GCC4.6, Mono
2.6.7, Mono 2.10.1), Arch Linux (with GCC 4.6, Mono 2.10.2) and no success.
I've tried loading libmono directly with dlload, dlloading mono via a
dlloaded library and as in the example below.

all: main.cpp mymono.c
    gcc -shared -fPIC -Wl,-soname,libmymono.so `pkg-config --cflags --libs
mono-2` -o libmymono.so mymono.c
    g++ -ldl main.cpp -o app

#include <mono/jit/jit.h>

MonoDomain* domain;

void init(void)
    printf("Init called\n");
    domain = mono_jit_init("libmymono.so");

#include <stdio.h>
#include <dlfcn.h>

int loadUnloadMonoLibrary()
    void* mono_library;

    mono_library = dlopen("./libmymono.so", RTLD_NOW);
    if(mono_library == NULL) {
        return 1;

    void* initializer = dlsym(mono_library, "init");
    if(initializer == NULL) {
        return 2;

    typedef void (*mono_init_function_type)(void);
        mono_init_function_type func;
        void * obj;
    } alias;
    alias.obj = initializer;
    mono_init_function_type init_func = alias.func;



    return 0;

int main()
    int i = loadUnloadMonoLibrary();
    int j = loadUnloadMonoLibrary();
    printf("Status %i %i\n", i, j);
    return j;


2011/5/16 Martin Arvidssson <martin.arvidsson at gmail.com>

> Thanks, I will try the dynamic loading. Global variables are gone after my
> driver is restarted from the host application.

View this message in context: http://mono.1490590.n4.nabble.com/Embedding-Mono-multiple-calls-to-mono-jit-init-tp3519842p3537932.html
Sent from the Mono - Dev mailing list archive at Nabble.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20110520/44d7b3a4/attachment.html 

More information about the Mono-devel-list mailing list