comp.lang.ada
 help / color / mirror / Atom feed
* calling Ada dll from C?
@ 2015-03-21  9:43 Stephen Leake
  2015-03-21 14:19 ` Simon Wright
  0 siblings, 1 reply; 6+ messages in thread
From: Stephen Leake @ 2015-03-21  9:43 UTC (permalink / raw)


I'm using an OpenToken parser with Emacs. In order to make it as fast as
possible, I'm trying to build the parser as a dynamically linked library
(.dll or .so); Emacs 25 will have the ability to load dlls at run time.

I can build the dll with a library project file:

   for Library_Name use "ada_wisi_module_parse";
   for Library_Dir use "lib";
   for Library_Kind use "dynamic";

However, when I try to load that dll into Emacs, it complains with "the
module cannot be found". Of course, it doesn't say _which_ module cannot
be found - sigh.

I get the same error on Windows 7 32 bit and Debian 64 bit. I'm
compiling with GNAT GPL 2014.

On Debian, ldd says all required libraries are found.


A related issue is 'adainit'. According to "(gnat_ugn) Binding with
Non-Ada Main Programs", since the main program is not in Ada, I'm
supposed to run gnatbind with -n, and then call 'adainit' from the C
main program.

However, since I'm only building a dll, not a main program, it appears
gnatbind is not run, so no 'adainit' is generated.


Has anyone build an Ada dll that can be called from C?

-- 
-- Stephe

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: calling Ada dll from C?
  2015-03-21  9:43 calling Ada dll from C? Stephen Leake
@ 2015-03-21 14:19 ` Simon Wright
  2015-03-23  7:23   ` Stephen Leake
  0 siblings, 1 reply; 6+ messages in thread
From: Simon Wright @ 2015-03-21 14:19 UTC (permalink / raw)


Stephen Leake <stephen_leake@stephe-leake.org> writes:

> A related issue is 'adainit'. According to "(gnat_ugn) Binding with
> Non-Ada Main Programs", since the main program is not in Ada, I'm
> supposed to run gnatbind with -n, and then call 'adainit' from the C
> main program.
>
> However, since I'm only building a dll, not a main program, it appears
> gnatbind is not run, so no 'adainit' is generated.

You need to build a 'stand-alone library'[1]. If the library is dynamic,
the default is to do automatic initialization (i.e. elaboration) on load
(and finalization on unload?).

[1] http://docs.adacore.com/gprbuild-docs/html/share/gnat_project_manager.html#stand-alone-library-projects

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: calling Ada dll from C?
  2015-03-21 14:19 ` Simon Wright
@ 2015-03-23  7:23   ` Stephen Leake
  2015-03-23  8:36     ` Dmitry A. Kazakov
                       ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Stephen Leake @ 2015-03-23  7:23 UTC (permalink / raw)


Simon Wright <simon@pushface.org> writes:

> Stephen Leake <stephen_leake@stephe-leake.org> writes:
>
>> A related issue is 'adainit'. According to "(gnat_ugn) Binding with
>> Non-Ada Main Programs", since the main program is not in Ada, I'm
>> supposed to run gnatbind with -n, and then call 'adainit' from the C
>> main program.
>>
>> However, since I'm only building a dll, not a main program, it appears
>> gnatbind is not run, so no 'adainit' is generated.
>
> You need to build a 'stand-alone library'[1]. If the library is dynamic,
> the default is to do automatic initialization (i.e. elaboration) on load
> (and finalization on unload?).

Thanks for the pointer, but that did not help.

I made it work by building a static Ada library, running gnatbind -n on
that directly to generate adainit, writing a C wrapper to call adainit,
and building the dll by linking together the C wrapper, the Ada static
library and the GNAT runtime using 'gcc -shared'.

However, that only works on Windows; Debian still gives "file not
found".

Does anyone know why the loader does not say _which_ file is not found?
It is _extremely_ frustrating to not be able to better diagnose this!

I guess I can use a simple C main (rather than Emacs, to reduce the
number of files accessed), and try strace.

-- 
-- Stephe


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: calling Ada dll from C?
  2015-03-23  7:23   ` Stephen Leake
@ 2015-03-23  8:36     ` Dmitry A. Kazakov
  2015-03-23 13:42     ` Patrick Noffke
  2015-03-25 20:48     ` Stephen Leake
  2 siblings, 0 replies; 6+ messages in thread
From: Dmitry A. Kazakov @ 2015-03-23  8:36 UTC (permalink / raw)


On Mon, 23 Mar 2015 02:23:51 -0500, Stephen Leake wrote:

> Does anyone know why the loader does not say _which_ file is not found?
> It is _extremely_ frustrating to not be able to better diagnose this!

Yes. Maybe it is (under Windows) because GUI vs. console.

> I guess I can use a simple C main (rather than Emacs, to reduce the
> number of files accessed), and try strace.

That is what I did in such cases. E.g. when running from under GPS, I had
no error message dialog with the missing DLLs. When I ran it from the cmd
console I saw the dialog. In my case it were GNAT run-time DLLs missing.

BTW, I never managed to make Ada DLLs working under Windows. It seems too
many subtle settings required.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: calling Ada dll from C?
  2015-03-23  7:23   ` Stephen Leake
  2015-03-23  8:36     ` Dmitry A. Kazakov
@ 2015-03-23 13:42     ` Patrick Noffke
  2015-03-25 20:48     ` Stephen Leake
  2 siblings, 0 replies; 6+ messages in thread
From: Patrick Noffke @ 2015-03-23 13:42 UTC (permalink / raw)


On Monday, March 23, 2015 at 2:23:54 AM UTC-5, Stephen Leake wrote:
> Simon Wright writes:
> 
> > Stephen Leake writes:
> >
> >> A related issue is 'adainit'. According to "(gnat_ugn) Binding with
> >> Non-Ada Main Programs", since the main program is not in Ada, I'm
> >> supposed to run gnatbind with -n, and then call 'adainit' from the C
> >> main program.
> >>
> >> However, since I'm only building a dll, not a main program, it appears
> >> gnatbind is not run, so no 'adainit' is generated.
> >
> > You need to build a 'stand-alone library'[1]. If the library is dynamic,
> > the default is to do automatic initialization (i.e. elaboration) on load
> > (and finalization on unload?).
> 
> Thanks for the pointer, but that did not help.
> 
> I made it work by building a static Ada library, running gnatbind -n on
> that directly to generate adainit, writing a C wrapper to call adainit,
> and building the dll by linking together the C wrapper, the Ada static
> library and the GNAT runtime using 'gcc -shared'.
> 
> However, that only works on Windows; Debian still gives "file not
> found".
> 
> Does anyone know why the loader does not say _which_ file is not found?
> It is _extremely_ frustrating to not be able to better diagnose this!
> 

Did you try using strace?

Is it as simple as setting your LD_LIBRARY_PATH environment variable?

Pat

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: calling Ada dll from C?
  2015-03-23  7:23   ` Stephen Leake
  2015-03-23  8:36     ` Dmitry A. Kazakov
  2015-03-23 13:42     ` Patrick Noffke
@ 2015-03-25 20:48     ` Stephen Leake
  2 siblings, 0 replies; 6+ messages in thread
From: Stephen Leake @ 2015-03-25 20:48 UTC (permalink / raw)


Stephen Leake <stephen_leake@stephe-leake.org> writes:

> Simon Wright <simon@pushface.org> writes:
>
>> Stephen Leake <stephen_leake@stephe-leake.org> writes:
>>
>>> A related issue is 'adainit'. According to "(gnat_ugn) Binding with
>>> Non-Ada Main Programs", since the main program is not in Ada, I'm
>>> supposed to run gnatbind with -n, and then call 'adainit' from the C
>>> main program.
>>>
>>> However, since I'm only building a dll, not a main program, it appears
>>> gnatbind is not run, so no 'adainit' is generated.
>>
>> You need to build a 'stand-alone library'[1]. If the library is dynamic,
>> the default is to do automatic initialization (i.e. elaboration) on load
>> (and finalization on unload?).
>
> Thanks for the pointer, but that did not help.
>
> I made it work by building a static Ada library, running gnatbind -n on
> that directly to generate adainit, writing a C wrapper to call adainit,
> and building the dll by linking together the C wrapper, the Ada static
> library and the GNAT runtime using 'gcc -shared'.
>
> However, that only works on Windows; Debian still gives "file not
> found".

This was because I'm using the libre GNAT distribution, rather than the
Debian gnat distribution. So I had to set LD_LIBRARY_PATH. I used strace
to find this, but ldd also reported it (not sure why I missed that the
first time I tried ldd).

So now I have an Ada dynamic library that works with Emacs on either
Windows or Debian.

-- 
-- Stephe

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2015-03-25 20:48 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-21  9:43 calling Ada dll from C? Stephen Leake
2015-03-21 14:19 ` Simon Wright
2015-03-23  7:23   ` Stephen Leake
2015-03-23  8:36     ` Dmitry A. Kazakov
2015-03-23 13:42     ` Patrick Noffke
2015-03-25 20:48     ` Stephen Leake

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