[Mono-dev] Calling the mcs from an app.

Frank Fuchs fk.fuchs at googlemail.com
Sun Jul 25 15:08:24 EDT 2010


Hi,

answering myself her. I almost works. I get a compiled assembly as the result of the following calls from c++:

	MonoDomain* child = mono_domain_create_appdomain("MooseQT Compiler Domain",NULL);
        mono_domain_set(child,0);
	MonoAssembly* assembly = mono_domain_assembly_open(mono_domain_get(), "/Users/fuchs/Work/Codes/Libraries/mono_160737/lib/mono/2.0/gmcs.exe");
	if (!assembly)
		exit (2);
	MonoClass *klass;
	MonoMethod *method = NULL, *m = NULL;
	klass = mono_class_from_name(mono_assembly_get_image(assembly), "Mono.CSharp", "Driver");	
	gpointer iter=NULL;
	
	while ((m = mono_class_get_methods (klass, &iter))) 
	{
		if (strcmp (mono_method_get_name (m), "Main") == 0) 
			method = m;
	}

	gpointer args[1];	
	args [0] = mono_array_new(mono_domain_get(),mono_get_string_class(), 1);
	MonoString* string_mono=mono_string_new(mono_domain_get(), "/Users/fuchs/Documents/Eclipse/MooseQT/ScriptTests/Mono/mono.2.6.4/test_hello.cs");
	mono_array_set((MonoArray*)args[0], gpointer, 0, string_mono);
	mono_runtime_invoke(method, NULL, args, NULL);
	mono_domain_set(mpDomain,10000);
	mono_domain_unload(child);  	

However, the hosting app stops/ crashes due to the Environment.Exit() calls in Moose.CSharp.Driver.Main. 
Can this be circumvented somehow? Can I ignore these Exit statements somehow ... why do they act beyond the JIT?

-Frank




Am 24.07.2010 um 22:53 schrieb Frank Fuchs:

> Hi,
> 
> I want to test mono for embedding it into my C++ application. So far everything worked out rather well, but I'd like to have more of a script-like behavior. To be precise I'd like to provide the users of my application with the ability to write a rather complete .cs file (or even many of them) which interface with the methods of the host application. At the moment I need to invoke mcs manually in order to get this functionality (the assemblies are then executed with an embedded Jit ). However from browsing the web and the gmcs.exe assembly it seems possible to write a small c# program (which loads the gmcs.exe assembly) and invokes the compiler from source. Can the InvokeCompiler method in gmcs be called from outside? maybe even from c++? 
> 
> Thank you in advance!
> Frank



More information about the Mono-devel-list mailing list