[Mono-devel-list] Mono runtime for C compilation problem

André Fontenele andre at ironhousefund.com
Thu Aug 26 13:52:36 EDT 2004


Help!

	I've been trying to run some routines on mono so that I can use them on
my PostgreSQL Linux server as a stored procedure. Since there seems to
be no way to do this directly, I decided to do it with the
/usr/include/mono/ libraries on the runtime-devel rpm: C# -> Mono
Runtime -> C -> libpq -> PostgreSQL.
	The problem is with the Mono Runtime -> C part. I got this sample
(attached) from a list and tried to compile it in a thousand of
different ways, but it keeps giving me this error:

> /franke/a.c: In function `setup':
> /franke/a.c:35: error: dereferencing pointer to incomplete type
> /franke/a.c: In function `main':
> /franke/a.c:67: error: dereferencing pointer to incomplete type

	For some reason, the compiler isn't able to access the structs inside
the libraries. I reinstalled the libraries from the scratch...
	I'm stuck in this problem for days now :.(
	Can anyone give me an idea on what may be wrong? Or send me another
example of what worked when you tried to use the mono runtime in C
programs? I tried the example on the mono site, but that didn't help
much, since the code seems to use the same structs...

	Txs,
	Andre Fontenele
	IronHouse Fund


#include <mono/mini/jit.h>
#include <mono/metadata/environment.h>
#include <mono/metadata/debug-helpers.h>
#include <mono/metadata/loader.h>
#include <mono/metadata/mono-debug.h>

static MonoDomain *domain;
static MonoAssembly *assembly;

/*
 * Very simple mono embedding example.
 * Compile with: 
 * 	gcc -o teste teste.c `pkg-config --cflags --libs mono` -lm
 * 	mcs test.cs
 * Run with:
 * 	./teste test.exe
 */
static void setup()
{
	assembly = mono_domain_assembly_open(domain, "test.dll");
	if(assembly==NULL)
	{
		printf("could not load assembly\n");
		mono_environment_exitcode_set(-1);
	}
	else
	{
		printf("assembly loaded succesfully\n");
		mono_debug_init_2(assembly);
		domain->entry_assembly=assembly; //HERE'S THE PROBLEM!!!
		mono_environment_exitcode_set(0);
	}
}

int main(int argc, char* argv[])
{
	//MonoClass * class;	
	//MonoDomain *domain;
	MonoMethod *method;
	MonoMethodDesc *methodDesc;
	//MonoObject *returnedMonoObject;	
	gpointer params[1];

	domain = mono_jit_init ("TestDomain");
	if(domain == NULL)
	{
		printf("could not init domain\n");
		return 0;	
	}
	mono_debug_init(domain, MONO_DEBUG_FORMAT_MONO);
	mono_runtime_exec_managed_code(domain, setup, NULL);
			

	// Create the method description	
	methodDesc = mono_method_desc_new("TestNamespace.test:foo", TRUE);
	if(!methodDesc)
		printf("Error in creating methodDesc \n");
	else
		printf("methodDesc created succesfully\n");
	
	// Search the above method description in image
	method = mono_method_desc_search_in_image(methodDesc, assembly->image);
//AND HERE TOO!!!
	if(!method)
		printf("Method could not be located in class \n");
	else
		printf("Method located successfully\n");

	// invoke method
	params[0]= mono_string_new(domain, "TestFile.txt"); 	
	mono_runtime_invoke(method, NULL, params, NULL );

	mono_jit_cleanup (domain);
	return 1;
}




More information about the Mono-devel-list mailing list