[Mono-dev] Integrating C# and already existing C sources using GAPI or something similar

Mario Sánchez msanchez at igalia.com
Mon Jan 23 06:39:31 EST 2006

Hi, this is my first message to this list, so I'll try to do it my

I'm currently working at a Gtk application and now I'm trying to make an
small part of the already-made gtk interface (a simple use case of the
whole application) using Mono with Gtk#, to see how this integration
could work. As you can imagine, I'd like to use the most already written
source code I can, so I'd like to call already written C functions from
my new C# interface, using a Wrapper for that purpose. And this is the
point in which I'm now stalled: 

I'm using Gapi (http://www.mono-project.com/GAPI) to automatically
generate wrappers of the base C application and I've founded these

  1.- I'd like to generate wrappers for a source directory and
sub-directories of a currently installed library, and I don't know
how to make this without explicitly specify those directories one-by-one
in the parsing gapi source file, as you can see here:
<api filename="libfisterra_client-gapi_output.xml">
 <library name="libfisterra-client">
  <namespace name="MonoWrappers.Libfisterra.Client">

<api filename="libfisterra_client_common-gapi_output.xml">
 <library name="libfisterra-client">
  <namespace name="MonoWrappers.Libfisterra.Client.Common">
...and after doing that, generate the desired library with this command:

mcs -pkg:gtk-sharp-2.0 -target:library -unsafe
-out:(BUILD_DIR)/libfisterra-client-mono.dll libfisterra/client/*.cs

As you can see this doesn't seem to be a very good way of doing that. I
imagine that there's a way of doing this without defining two <api>
sections for the sources of a directory and sub-directories, but i don't
know what is. Furthermore, the sub-directory 'common' compiles properly
after parsing process, but there also is another directory inside
'client' one (called 'client/shell') that I cannot to compile using this
'technique', because Gobjects defined there are sub-classes of Gobjects
defined on 'client' and it seems that the Gapi code generator doesn't
find those classes when compiling the library. I tried to use the
gapi2-fixup command to adapt the output xml file generated by the
parsing process and I got no successfully result.

  2.-I have more source code that I'd like to re-use but that is not
installed as a library, because it's not a library but an application
(the application in which I'm trying to re-implement a use case in Mono
terms), but it has got, for example, several defined Gobjects and
utilities that are useful for me to use from my Gtk# interface. The
question is how could I automatically wrap those sources using Gapi (or
something similar) into C# files, in order not to have to implement that
already-written functionality again.

  3.- Another question using GAPI is how to wrap C sources that not
correspond to GObject classes because, as I was able to see, gapi parser
only recognizes those sources that represent classes using GObject, but
not those other C sources as could be utility libraries containing
useful functions for common situations at this application.

I'll be so glad if someone was able to help me, because I can't find
enough information and documentation about the Gapi parser across the
Internet, so I can't find the way to achieve this issues. I'm open to
other suggestions (not only Gapi) for me to integrate C# and C in the
way I mean too, so if someone knows a better way to do this I'll be
interested on it. 


More information about the Mono-devel-list mailing list