comp.lang.ada
 help / color / Atom feed
* Relocatable lib calling external C libs: undefined references
@ 2020-08-13 12:31 hreba
  0 siblings, 0 replies; only message in thread
From: hreba @ 2020-08-13 12:31 UTC (permalink / raw)


Trying for several days now, I don't get my project to link when I use 
relocatable libraries, and only then.

First, I made a thin binding to GSL (GNU Scientific Library). The .ads 
files were generated with "g++ -c -fdump-ada-spec ...",  with some 
corrections. The result used here is gsl_integration_h.ads.

 From that, I made a thick binding, called Integration.

And finally, I wrote a test program Test_Integration which imports a 
test function from package Test_Integ_Aux.

The subprogram call graph is
                                       Test_Integration
                                      /                \
   thick -->      Integration.Integration_QNG    Test_Integ_Aux.Circle
                        |
      gsl_integration_h.gsl_integration_qng     <-- thin

The project files are:

-- gsl_thin.gpr --

library project GSL_Thin is

    for Source_Dirs use (".");
    for Library_Dir use "lib";
    for Object_Dir use "obj";
    for Library_Name use "gsl_thin";
    for Library_Kind use "relocatable";
    for Externally_Built use "false";

    package Compiler is
       for Default_Switches ("ada") use ("-g");
    end Compiler;

    package Linker is
       for Linker_Options use ("-L/usr/lib/x86_64-linux-gnu", "-lgsl", 
"-lgslcblas");
    end Linker;

end GSL_Thin;

-- gsl.gpr --

with "Thin/gsl_thin";

library project GSL is

    for Source_Dirs use (".");
    for Object_Dir use "obj";
    for Library_Dir use "lib";
    for Library_Name use "gsl";
    for Library_Kind use "relocatable";
    for Library_Interface use ("Integration");
    for Externally_Built use "false";

    package Compiler is
       for Default_Switches ("ada") use ("-g");
    end Compiler;

    package Linker is
       for Linker_Options use ("-g");
    end Linker;

end GSL;

-- test_integration.gpr --

with "../Library/gsl";

project Test_Integration is

    for Source_Dirs use (".");
    for Object_Dir use "obj";
    for Exec_Dir use ".";
    for Main use ("test_integration.adb");

    package Compiler is
       for Default_Switches ("ada") use ("-g");
    end Compiler;

    package Linker is
       for Linker_Options use ("-g");
    end Linker;

end Test_Integration;


When I call gprbuild with the last one, I get

Compile
    [Ada]          test_integration.adb
    [Ada]          gsl_integration_h.ads
    [Ada]          gsl_math_h.ads
    [Ada]          integration.adb
    [Ada]          test_integ_aux.adb
Build Libraries
    [gprlib]       gsl_thin.lexch
    [gprlib]       gsl.lexch
    [link library] libgsl_thin.so
    [bind SAL]     gsl
    [Ada]          b__gsl.adb
    [link library] libgsl.so
Bind
    [gprbind]      test_integration.bexch
    [Ada]          test_integration.ali
Link
    [link]         test_integration.adb
/opt/GNAT/2020/bin/../libexec/gcc/x86_64-pc-linux-gnu/9.3.1/ld: 
/home/frank/Temp/Test/Library/lib//libgsl.so: undefined reference to 
`gsl_integration_qng'
collect2: error: ld returned 1 exit status
gprbuild: link of test_integration.adb failed
gprbuild: failed command was: /opt/GNAT/2020/bin/gcc test_integration.o 
b__test_integration.o /home/frank/Temp/Test/Test/obj/test_integ_aux.o 
-L/home/frank/Temp/Test/Library/lib/ -lgsl 
-L/home/frank/Temp/Test/Library/Thin/lib/ -lgsl_thin -g 
-L/usr/lib/x86_64-linux-gnu -lgsl -lgslcblas 
-L/home/frank/Temp/Test/Test/obj/ -L/home/frank/Temp/Test/Test/obj/ 
-L/home/frank/Temp/Test/Library/lib/ 
-L/home/frank/Temp/Test/Library/Thin/lib/ 
-L/opt/GNAT/2020/lib/gcc/x86_64-pc-linux-gnu/9.3.1/adalib/ 
-shared-libgcc -lgnat-2020 -ldl 
-Wl,-rpath-link,/opt/GNAT/2020/lib/gcc/x86_64-pc-linux-gnu/9.3.1//adalib 
-Wl,-z,origin,-rpath,$ORIGIN/..//Library/lib:$ORIGIN/..//Library/Thin/lib:/usr/lib/x86_64-linux-gnu:$ORIGIN//obj:/opt/GNAT/2020/lib/gcc/x86_64-pc-linux-gnu/9.3.1/adalib:/opt/GNAT/2020/lib64:/opt/GNAT/2020/lib 
-o /home/frank/Temp/Test/Test//test_integration

When I look with nm into libgsl.so I see indeed gsl_integration_qng 
undefined:
                  U gsl_integration_qng
and a little below:
0000000000002090 T integration__integration_qng

When compiling the libraries as static, the program works, but whatever 
project variation I try with relocatable ones, I get this linking error. 
I even made some simpler examples with relocatable libraries and without 
external C libraries, with corresponding project files, and they all 
work. So I don't know what to try else.

-- 
Frank Hrebabetzky, Kronach	+49 / 9261 / 950 0565

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

only message in thread, back to index

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-13 12:31 Relocatable lib calling external C libs: undefined references hreba

comp.lang.ada

Archives are clonable: git clone --mirror https://archive.legitdata.co/comp.lang.ada

Example config snippet for mirrors


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git