comp.lang.ada
 help / color / mirror / Atom feed
* Shared Ada Library to be Used in a Non-Ada Context
@ 2005-08-08 23:35 David Sauvage
  2005-08-09  2:50 ` Jeffrey Carter
  2005-08-10  7:38 ` Ludovic Brenta
  0 siblings, 2 replies; 11+ messages in thread
From: David Sauvage @ 2005-08-08 23:35 UTC (permalink / raw)



Hi, I'm trying to make a simple illustration (that work) of building an
Ada shared library
to be Used in a Non-Ada Context (errors & sources below)
I think i got problems during my build process or i'm wrong somewhere
else ;-)
Any tips ? thanks ;-)

David

CASE 1 : using gnatbind -Lservices libservices
-------
exemple$ make
gnatmake -fPIC  -Wall  -c libservices.adb
gcc-3.4 -c -fPIC -Wall libservices.adb
gnatbind  -Lservices libservices
gcc -g -fPIC -Wall -c b~libservices.adb
gcc: installation problem, cannot exec `gnat1': Aucun fichier ou
r�pertoire de ce type
make: *** [libservices.so] Erreur 1

CASE 2 : using gnatbind -C -Lservices libservices
-------
exemple$ make
gnatmake -fPIC  -Wall  -c libservices.adb
gcc-3.4 -c -fPIC -Wall libservices.adb
gnatbind -C -Lservices libservices
gcc -g -fPIC -Wall -c b_libservices.c
gcc -g -fPIC -Wall -shared -W1,-soname,libservices.so -o libservices.so
b_libservices.o
gcc -L. -lservices -o main
/usr/lib/gcc-lib/i486-linux/3.3.5/../../../crt1.o(.text+0x18): In
function `_start':
../sysdeps/i386/elf/start.S:98: undefined reference to `main'
./libservices.so: undefined reference to `system__secondary_stack___elabb'
./libservices.so: undefined reference to `__gnat_handler_installed'
./libservices.so: undefined reference to `system__soft_links___elabb'
./libservices.so: undefined reference to `system__secondary_stack_E'
./libservices.so: undefined reference to `ada__exceptions___elabs'
./libservices.so: undefined reference to `__gnat_set_globals'
./libservices.so: undefined reference to `system__exception_table_E'
./libservices.so: undefined reference to `system__exceptions___elabs'
./libservices.so: undefined reference to `libservices_E'
./libservices.so: undefined reference to `__gnat_install_handler'
./libservices.so: undefined reference to `system__soft_links_E'
./libservices.so: undefined reference to `ada__exceptions___elabb'
./libservices.so: undefined reference to `system__exceptions_E'
./libservices.so: undefined reference to
`system__standard_library__adafinal'
./libservices.so: undefined reference to `system__exception_table___elabb'
./libservices.so: undefined reference to `ada__exceptions_E'
collect2: ld a retourn� 1 code d'�tat

Files listings :
main.c
libservices.adb
libservices.ads
Makefile

>>>>>>>>>>>>>>>>>> main.c <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

#include <stdio.h>

//----- shared library interfaces

/* the library elaboration procedure  */
extern void servicesinit (void);

/* the library finalization procedure */
extern void servicesfinal (void);

/* the library service method         */
extern void service_1 (void);

//----- application main method

int main(int argc, char **argv)
{
  servicesinit();

  service_1 ();

  servicesfinal ();

  return 1;
}

>>>>>>>>>>>>>>>>>> libservices.adb <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

package body Libservices is

	-- -------------------
	procedure Service_1 is
	begin
   		null;
	end Service_1;

end Libservices;


>>>>>>>>>>>>>>>>>> libservices.ads <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

package Libservices is

	-- -------------------
	procedure Service_1;
	pragma Export(C, Service_1, "service_1");

end Libservices;


>>>>>>>>>>>>>>>>>> Makefile <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

OBJS = libservices.so main

all : $(OBJS)

libservices.so : libservices.adb libservices.ads
	gnatmake -fPIC  -Wall  -c libservices.adb

# CASE 1 :
	gnatbind  -Lservices libservices
	gcc -g -fPIC -Wall -c b~libservices.adb
	gcc -g -fPIC -Wall -shared -W1,-soname,libservices.so -o libservices.so
b~libservices.o

# CASE 2 :
#	gnatbind -C -Lservices libservices
#	gcc -g -fPIC -Wall -c b_libservices.c
#	gcc -g -fPIC -Wall -shared -W1,-soname,libservices.so -o
libservices.so b_libservices.o

main : libservices.so main.c
	gcc -L. -lservices -o main
	
clean :
	rm -f *.o *.ali b~* *~	b_libservices.c libservices.so



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

* Re: Shared Ada Library to be Used in a Non-Ada Context
  2005-08-08 23:35 Shared Ada Library to be Used in a Non-Ada Context David Sauvage
@ 2005-08-09  2:50 ` Jeffrey Carter
  2005-08-09 21:51   ` David Sauvage
  2005-08-10  7:38 ` Ludovic Brenta
  1 sibling, 1 reply; 11+ messages in thread
From: Jeffrey Carter @ 2005-08-09  2:50 UTC (permalink / raw)


David Sauvage wrote:
> 
> CASE 1 : using gnatbind -Lservices libservices
> -------
> exemple$ make
> gnatmake -fPIC  -Wall  -c libservices.adb
> gcc-3.4 -c -fPIC -Wall libservices.adb

Gnatmake invokes "gcc-3.4". It seems to know about GNAT.

> gnatbind  -Lservices libservices
> gcc -g -fPIC -Wall -c b~libservices.adb

Gnatbind invokes "gcc". It doesn't seem to know about GNAT.

> gcc: installation problem, cannot exec `gnat1': Aucun fichier ou
> r�pertoire de ce type
> make: *** [libservices.so] Erreur 1
> 
> CASE 2 : using gnatbind -C -Lservices libservices

Same thing.

-- 
Jeff Carter
"Whatever it is, I'm against it."
Horse Feathers
46



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

* Re: Shared Ada Library to be Used in a Non-Ada Context
  2005-08-09  2:50 ` Jeffrey Carter
@ 2005-08-09 21:51   ` David Sauvage
  2005-08-10  0:14     ` Georg Bauhaus
  2005-08-10  7:53     ` Ludovic Brenta
  0 siblings, 2 replies; 11+ messages in thread
From: David Sauvage @ 2005-08-09 21:51 UTC (permalink / raw)


Jeffrey Carter wrote:
...
> Gnatmake invokes "gcc-3.4". It seems to know about GNAT.
...
> Gnatbind invokes "gcc". It doesn't seem to know about GNAT.
...
> Same thing.

Hi thanks for your help, i forgot to list my system configuration,
Now, gcc-3.4 is used everywhere in the Makefile, and i still got the
same problem ...
i'm now working on my gcc & gnat packages as my system may be fluzzy.

i'm using Debian GNU/Linux Sarge.
linux kernel     2.6.8-2-386
libc6               2.3.2.ds1-22

gcc                3.3.5-3
gcc-3.3          3.3.5-13
gcc-3.4          3.4.3-13

gnat-3.4          3.4.3-13
libgnat-3.4      3.4.3-13
libgnat-3.15p- 3.15p-1

David



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

* Re: Shared Ada Library to be Used in a Non-Ada Context
  2005-08-09 21:51   ` David Sauvage
@ 2005-08-10  0:14     ` Georg Bauhaus
  2005-08-10  7:53     ` Ludovic Brenta
  1 sibling, 0 replies; 11+ messages in thread
From: Georg Bauhaus @ 2005-08-10  0:14 UTC (permalink / raw)


David Sauvage wrote:
> Jeffrey Carter wrote:
> ...
> 
>>Gnatmake invokes "gcc-3.4". It seems to know about GNAT.
> 
> ...
> 
>>Gnatbind invokes "gcc". It doesn't seem to know about GNAT.

> i'm using Debian GNU/Linux Sarge.

> libgnat-3.4      3.4.3-13
> libgnat-3.15p- 3.15p-1
> 

This looks suspicious, how many GNATs does your system have,
visible in PATH? "gcc" could be the name of the program that
is invoked by the gnattools. There is a switch, --GCC IIRC,
that you can use to instruct the tools to choose the correct
compiler driver.


-- Georg




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

* Re: Shared Ada Library to be Used in a Non-Ada Context
  2005-08-08 23:35 Shared Ada Library to be Used in a Non-Ada Context David Sauvage
  2005-08-09  2:50 ` Jeffrey Carter
@ 2005-08-10  7:38 ` Ludovic Brenta
  1 sibling, 0 replies; 11+ messages in thread
From: Ludovic Brenta @ 2005-08-10  7:38 UTC (permalink / raw)


David Sauvage wrote:
> main : libservices.so main.c
>        gcc -L. -lservices -o main

You don't seem to be compiling main.c, are you?

You probably need "$(CC) -o main main.c $(CFLAGS) -L. -lservices".

-- 
Ludovic Brenta.




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

* Re: Shared Ada Library to be Used in a Non-Ada Context
  2005-08-09 21:51   ` David Sauvage
  2005-08-10  0:14     ` Georg Bauhaus
@ 2005-08-10  7:53     ` Ludovic Brenta
  2005-08-10 22:02       ` David Sauvage
  1 sibling, 1 reply; 11+ messages in thread
From: Ludovic Brenta @ 2005-08-10  7:53 UTC (permalink / raw)


Jeffrey Carter wrote:
> Gnatmake invokes "gcc-3.4". It seems to know about GNAT.
> Gnatbind invokes "gcc". It doesn't seem to know about GNAT.

This appears to be a bug in the gnat-3.4 package.

David Sauvage wrote:
> i'm using Debian GNU/Linux Sarge.
> linux kernel     2.6.8-2-386
> libc6               2.3.2.ds1-22
> gcc                3.3.5-3
> gcc-3.3          3.3.5-13
> gcc-3.4          3.4.3-13
> gnat-3.4          3.4.3-13
> libgnat-3.4      3.4.3-13
> libgnat-3.15p- 3.15p-1

You should use the system C compiler (gcc-3.3) and the system Ada
compiler (gnat). I suggest you remove gnat-3.4 and reinstall gnat.
This will make your toolchain consistent with all other Ada
packages in Sarge.

Your Makefile should use CC=gcc, and gnatmake directly. In Sarge,
gcc is a symlink to gcc-3.3; gnatmake and gnatkink correctly
invoke gnatgcc, the Ada-aware gcc 2.8.1 compiler driver.

Your Makefile should link libservices.so to libgnat explicitly.
See the Debian Ada Policy[1] for detailed instructions on how to
do this.

[1] http://www.ada-france.org/debian/debian-ada-policy.html

-- 
Ludovic Brenta.




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

* Re: Shared Ada Library to be Used in a Non-Ada Context
  2005-08-10  7:53     ` Ludovic Brenta
@ 2005-08-10 22:02       ` David Sauvage
  2005-08-11  8:08         ` Ludovic Brenta
  0 siblings, 1 reply; 11+ messages in thread
From: David Sauvage @ 2005-08-10 22:02 UTC (permalink / raw)


Ludovic Brenta wrote:
> You should use the system C compiler (gcc-3.3) and the system Ada
> compiler (gnat). I suggest you remove gnat-3.4 and reinstall gnat.
> This will make your toolchain consistent with all other Ada
> packages in Sarge.
>...
Hi, thanks a lot for your tips !
i removed gnat-3.4, install gnat and update the Makefile [2]

i replaced "$(CC) $(CFLAGS) -c b~libservices.adb" by "gnatgcc $(CFLAGS)
-c b~libservices.adb"
as the first line give me "gcc: installation problem, cannot exec
`gnat1': Aucun fichier ou r�pertoire de ce type"

> Your Makefile should link libservices.so to libgnat explicitly.
Well i don't thing i figure out how to link libservices.so to the
libgnat the good way, but it work now.
I had "-L/usr/lib/gcc-lib/i486-linux/2.8.1/adalib/ -lgnat" at the end of
the library creation line, i'll keep searching.
After setting the LD_LIBRARY_PATH, it works !!

On the GNAT UG "Creating an Ada Library to be Used in a Non-Ada Context"
[1], i read about installing the library
so that it is not necessary to invoke the library elaboration and
finalization routines, interesting ... ;-)

[1]
http://gcc.gnu.org/onlinedocs/gcc-3.3.5/gnat_ug_unx/Creating-an-Ada-Library-to-be-Used-in-a-Non_002dAda-Context.html

[2] Makefile
OBJS = libservices.so main
CC = gcc
CFLAGS = -g -fPIC -Wall

all : $(OBJS)

libservices.so : libservices.adb libservices.ads
	gnatmake  -c libservices.adb
	gnatbind  -Lservices libservices
	gnatgcc -g -fPIC -c b~libservices.adb
	$(CC) $(CFLAGS) -shared -Wl,-soname,libservices.so.0 -o
libservices.so.0.0 b~libservices.o libservices.o
-L/usr/lib/gcc-lib/i486-linux/2.8.1/adalib/ -lgnat
	
main : libservices.so main.c
	$(CC) $(CFLAGS) -o main main.c -L. -lservices
	
clean :
	rm -f *.o *.ali b~* *~

--
David



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

* Re: Shared Ada Library to be Used in a Non-Ada Context
  2005-08-10 22:02       ` David Sauvage
@ 2005-08-11  8:08         ` Ludovic Brenta
  2005-08-11 10:41           ` Ludovic Brenta
  2005-08-11 23:26           ` David Sauvage
  0 siblings, 2 replies; 11+ messages in thread
From: Ludovic Brenta @ 2005-08-11  8:08 UTC (permalink / raw)


David Sauvage wrote:
> Well i don't thing i figure out how to link libservices.so to the
> libgnat the good way, but it work now.  I had
> "-L/usr/lib/gcc-lib/i486-linux/2.8.1/adalib/ -lgnat" at the end of
> the library creation line, i'll keep searching.  After setting the
> LD_LIBRARY_PATH, it works !!

Strange, /usr/lib/gcc-lib/i486-linux/2.8.1/adalib/libgnat.so should be
a symbolic link to /usr/lib/libgnat-3.15p.so.1.12, is that not the
case?  What does 'ldd libservices.so.0.0' and 'ldd main' say?

-- 
Ludovic Brenta.




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

* Re: Shared Ada Library to be Used in a Non-Ada Context
  2005-08-11  8:08         ` Ludovic Brenta
@ 2005-08-11 10:41           ` Ludovic Brenta
  2005-08-11 11:27             ` Georg Bauhaus
  2005-08-11 23:26           ` David Sauvage
  1 sibling, 1 reply; 11+ messages in thread
From: Ludovic Brenta @ 2005-08-11 10:41 UTC (permalink / raw)


Here is a complete, working Makefile.  gnatlink links
libservices.so.0.0 against libgnat properly.  When running main, you
need to set LD_LIBRARY_PATH so that the dynamic linker finds
libservices.so.0.

libservices.so.0.0 contains the actual shared library.
libservices.so.0 is needed when running main, because of the soname.
libservices.so is needed when linking main, because of -lservices.

This Makefile should work on any unix-like OS.

HTH

--
Ludovic Brenta.

CC := gcc
CFLAGS := -g -O2
ADAFLAGS := -g -O2 -gnatafno -gnatVa -fstack-check

main: main.o libservices.so
	$(CC) -o $@ $< -L. -lservices

libservices.so: $(wildcard libservices.ad[bs])
	gnatmake -c $(ADAFLAGS) libservices.adb
	gnatbind -Lservices libservices.ali
	gnatlink -shared -o libservices.so.0.0 \
	   libservices.ali -Wl,-soname,libservices.so.0
	ln -s libservices.so.0.0 libservices.so.0
	ln -s libservices.so.0.0 libservices.so

%.o: %.c
	$(CC) -c -o $@ $(CFLAGS) $<

clean:
	-rm *.o *.ali b~* libservices.so* main

.PHONY: clean




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

* Re: Shared Ada Library to be Used in a Non-Ada Context
  2005-08-11 10:41           ` Ludovic Brenta
@ 2005-08-11 11:27             ` Georg Bauhaus
  0 siblings, 0 replies; 11+ messages in thread
From: Georg Bauhaus @ 2005-08-11 11:27 UTC (permalink / raw)


Ludovic Brenta wrote:

> ADAFLAGS := -g -O2 -gnatafno -gnatVa -fstack-check

I have had problems with -fstack-check when the main
program is in C. IIRC this is documented/has been
discussed with recent GCCs. JFTR.



-- Georg



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

* Re: Shared Ada Library to be Used in a Non-Ada Context
  2005-08-11  8:08         ` Ludovic Brenta
  2005-08-11 10:41           ` Ludovic Brenta
@ 2005-08-11 23:26           ` David Sauvage
  1 sibling, 0 replies; 11+ messages in thread
From: David Sauvage @ 2005-08-11 23:26 UTC (permalink / raw)


Ludovic Brenta wrote:
> Strange, /usr/lib/gcc-lib/i486-linux/2.8.1/adalib/libgnat.so should be
> a symbolic link to /usr/lib/libgnat-3.15p.so.1.12, is that not the
> case?

ye it is, well, i was doing :
gcc -g -fPIC -Wall -shared -Wl,-soname,libservices.so.0 -o
libservices.so.0.0 b~libservices.o libservices.o
instead of :
gnatlink -g -fPIC -Wall -shared -Wl,-soname,libservices.so.0 -o
libservices.so.0.0 libservices.ali
May be that's why my lib was not linked to libgnat properly

I've try your Makefile and all work fine, thanks.

--
David



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

end of thread, other threads:[~2005-08-11 23:26 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-08-08 23:35 Shared Ada Library to be Used in a Non-Ada Context David Sauvage
2005-08-09  2:50 ` Jeffrey Carter
2005-08-09 21:51   ` David Sauvage
2005-08-10  0:14     ` Georg Bauhaus
2005-08-10  7:53     ` Ludovic Brenta
2005-08-10 22:02       ` David Sauvage
2005-08-11  8:08         ` Ludovic Brenta
2005-08-11 10:41           ` Ludovic Brenta
2005-08-11 11:27             ` Georg Bauhaus
2005-08-11 23:26           ` David Sauvage
2005-08-10  7:38 ` Ludovic Brenta

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