comp.lang.ada
 help / color / mirror / Atom feed
* Funny problem with libraries & GNAT (bug?)
@ 2011-02-15 21:40 mockturtle
  0 siblings, 0 replies; only message in thread
From: mockturtle @ 2011-02-15 21:40 UTC (permalink / raw)


Dear.all,
I was doing some experiments with libraries (using GNAT) and I stumbled on this strange problem. Let me give you an overview of the problem without the complete file set. Since the complete file set  is moderately large (~ 15K), I would post it in a separate message only if necessary. (I am hoping that someone could have some idea even without the whole file set).

My experiments are about dynamic loading and tagged object extension.  My setup is as follows: I have 3 libraries (hashers, dll and the one to be dynamically loaded) and one main file.  More precisely,

  # Hasher library
  * I have a package Hashers that define an abstract object Abstract_Hasher with a primitive procedure Digest.
  * I have two children packages Hashers.MD5 and Hashers.SHA1 that define extensions of Abstract_Hasher
  * Packages Hashers, Hashers.MD5 and Hashers.SHA1 are collected in a library libhashers.so
  * The files are in subdirectory Hashers/

  # DLL library
  * I have a package DLL that define a layer over the dlopen-type functions (to dynamically load libraries at run-time).
  * Package DLL is in a library of its own (libdll.so)
  * The files are in subdirectory DLL/

  # To be loaded
  * I have a third children package Hashers.Strange in a library libstrange.so of its own.  This library is to be loaded at runtime

  # Main program
  * The main program with-s Hashers and DLL and calls DLL.Open to load libstrange

The project files are as follows
  
-- Hashers/hashers.gpr 

project Hashers is
   for Object_Dir use "bin";
   for Library_Name use "hasher";
   for Library_Dir use "lib";
   for Library_Kind use "dynamic";
   for Library_Version use "1.0";
   for Library_Interface use ("Hashers", "Hashers.MD5", "Hashers.SHA1");
end Hashers;

-- DLL/dll.gpr

project DLL is
   for Object_Dir use "bin";
   for Library_Name use "dll";
   for Library_Dir use "lib";
   for Library_Kind use "dynamic";
   for Library_Version use "1.0";
end DLL;

-- test_dll_bad
with "DLL/dll";
with "Hasher/hashers";


project Test_dll_bad is
   for Main use ("main.adb");
   for Object_Dir use "bin";

   package Binder is
       for Default_Switches ("ada") use ("-largs", "-ldl");
   end Binder;
end Test_dll_bad;

-- test_hash_bad
with "Hasher/hashers";
with "DLL/dll";

project Test_hash_bad is
   for Main use ("main.adb");
   for Object_Dir use "bin";

   package Binder is
       for Default_Switches ("ada") use ("-largs", "-ldl");
   end Binder;

end Test_hash_bad;

Note that the only difference between test_dll_bad.gpr and test_hash_bad.gpr is the different order of the with's.

If I try to do

   gnatmake -Ptest_dll_bad

I get

  gnatlink /home/bernardi/Ada/prove/DLL-test/bin/main.ali -shared-libgcc -ldl 
  -L/home/bernardi/Ada/prove/DLL-test/Hasher/lib/ -lhasher 
  -L/home/bernardi/Ada/prove/DLL-test/DLL/lib/ -ldll 
  -Wl,-rpath,/home/bernardi/Ada/prove/DLL-test/Hasher/lib/:/home/bernardi/Ada/prove/DLL-test/DLL/lib/:/home/bernardi/gnat/lib/gcc/i686-pc-linux-gnu/4.3.4/adalib/ -o /home/bernardi/Ada/prove/DLL-test/bin/main
   b~main.o: In function `adainit':
   b~main.adb:(.text+0x3a9): undefined reference to `dll_E'
   b~main.adb:(.text+0x3b5): undefined reference to `dll___elabs'
   b~main.adb:(.text+0x3bb): undefined reference to `dll_E'
   /home/bernardi/Ada/prove/DLL-test/bin/main.o: In function `_ada_main':
   main.adb:(.text+0x58): undefined reference to `dll__open'

that is, the linker does not find the functions in libdll.so, despite the fact that it links it (see the -ldll) and the fact that the functions are there, for example,

   nm DLL/lib/libdll.so | grep dll__open

gives

   00000946 T dll__open
   00000b76 t dll__open__B_1__map_init_function.1448

If instead I use test_hash_bad (remember: with the with's exchanged), that is

    gnatmake -Ptest_hash_bad

then libhasher.so has problems

    gnatlink /home/bernardi/Ada/prove/DLL-test/bin/main.ali -shared-libgcc -ldl -L/home/bernardi/Ada/prove/DLL-test/DLL/lib/ -ldll -L/home/bernardi/Ada/prove/DLL-test/Hasher/lib/ -lhasher -Wl,-rpath,/home/bernardi/Ada/prove/DLL-test/DLL/lib/:/home/bernardi/Ada/prove/DLL-test/Hasher/lib/:/home/bernardi/gnat/lib/gcc/i686-pc-linux-gnu/4.3.4/adalib/ -o /home/bernardi/Ada/prove/DLL-test/bin/main
/home/bernardi/Ada/prove/DLL-test/bin/main.o: In function `_ada_main':
    main.adb:(.text+0x366): undefined reference to `hashers__get_hasher'

Now the linker does not find hashers__get_hasher, despite the -lhasher above and the fact that hashers__get_hasher is there 

    nm Hasher/lib/libhasher.so  | grep hashers__get_hasher

    0000e1e2 T hashers__get_hasher
    0000eb10 t hashers__get_hasher___clean.6583

Note that in both cases, the linker does not see the functions of the first with-ed library.

Any ideas?




^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2011-02-15 21:40 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-02-15 21:40 Funny problem with libraries & GNAT (bug?) mockturtle

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