comp.lang.ada
 help / color / mirror / Atom feed
From: Brian Drummond <brian@shapes.demon.co.uk>
Subject: Re: help bridging C and Ada
Date: Mon, 26 Mar 2012 10:03:37 +0000 (UTC)
Date: 2012-03-26T10:03:37+00:00	[thread overview]
Message-ID: <jkpeto$nk4$1@dont-email.me> (raw)
In-Reply-To: c4221180-bf2d-48d1-a161-c56435805200@b14g2000vbz.googlegroups.com

On Sun, 25 Mar 2012 06:37:02 -0700, Patrick wrote:

> I am having some luck with gnat's -fdump-ada-spec feature and I can use
> it to integrate simple C functions I have written.
> 
> However when I try to bind large libraries like gstreamer I end up with
> a sort of dependency hell. -fdump-ada-spec-slim just generates the one
> spec file but when I try to build with the generated spec, I get errors
> about other spec files missing. 

First : how many errors? Probably (hopefully) only a few, or from only a 
few further dependencies.

> Without the slim option I get about 100
> specs. I tried to "with" them all but I ended up with more errors about
> circular dependencies.

Only "with" what you need. One of the REALLY STRONG points about Ada is 
that YOU get to control what is visible and accessible in your program. 
As opposed to the complete mess that a couple of #includes can get you in 
C/C++. The huge binding you get with -fdump-ada-spec is just that mess 
made explicit...

I would use -fdump-ada-spec in one folder, just for reference.
Then use -slim in my project, and bring across the LEAST you can get away 
with from the -fdump-ada-spec folder to cover the missing dependencies. 
(The extra functions can be added to the gstreamer_slim.ads file, or a 
new gstreamer_extra.ads file, rather than adding complete files from -
fdump-ada-spec if you wish. That gives you more control)

This partly amounts to writing your own binding, as Simon suggested.
The other part is to create a package with Ada procedures and functions 
to interface to gstreamer, and use ONLY those functions everywhere else 
in your code. Then only that package needs to interface to the C code.

> that was with with Gstreamer and I had others errors when I tried the
> same process with gtk.

For GTK, there is already an Ada binding - representing a lot of work in 
itself - gtkada. The Glade GUI builder tool understands gtkada so it can 
do a lot of the work for you, though not everybody likes it, some want 
more control over the interface than Glade gives.

One point of warning about -fdump-ada-spec : it may still be a work in 
progress. It does a great job of interfacing to C, but some of the more 
advanced features of C++ give it problems - it has a good try at 
processing templates for example, but you have to finish the job. (I had 
to write dummy C++ code to instantiate each templated function I needed, 
so that the C++ compiler would actually generate code for them, to 
prevent linker errors. It didn't seem to understand they were being 
called from Ada.)

- Brian



  parent reply	other threads:[~2012-03-26 10:03 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-25 13:37 help bridging C and Ada Patrick
2012-03-25 14:52 ` Patrick
2012-03-25 17:00   ` Simon Wright
2012-03-25 17:47     ` Patrick
2012-03-26 13:45   ` Stephen Leake
2012-03-26 10:03 ` Brian Drummond [this message]
2012-03-26 12:05   ` J-P. Rosen
2012-03-26 22:03     ` Brian Drummond
2012-03-27  2:44       ` Patrick
2012-03-26 12:49   ` Marc C
2012-03-27 18:09 ` Shark8
2012-03-28  0:19   ` Patrick
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox