厚绑定动态库:未定义的引用

Thick binding dynamic library: Undefined references

到目前为止我在 Linux Mint 系统上做了什么:

  1. 编写 GSL 库的精简绑定
  2. 在瘦绑定的基础上写一个厚绑定
  3. 为1写一个测试程序
  4. 为2写一个测试程序

当我创建静态库时,一切正常。但是,在创建动态库时,编译 4. with

gprbuild -P test_odeiv2_dyn

获取未定义的引用:

Compile
   [Ada]          test_odeiv2.adb
   [Ada]          odeiv2_aux.adb
   [Ada]          integration.adb
   [Ada]          odeiv2.adb
Build Libraries
   [gprlib]       gsl.lexch
   [link library] libgsl.so
Bind
   [gprbind]      test_odeiv2.bexch
   [Ada]          test_odeiv2.ali
Link
   [link]         test_odeiv2.adb
/usr/bin/ld: /home/frank/Lib/Ada/Num/GSL/lib//libgsl.so: undefined reference to `gsl_odeiv2_driver_apply'
/usr/bin/ld: /home/frank/Lib/Ada/Num/GSL/lib//libgsl.so: undefined reference to `gsl_odeiv2_step_rk4imp'
/usr/bin/ld: /home/frank/Lib/Ada/Num/GSL/lib//libgsl.so: undefined reference to `gsl_odeiv2_step_msbdf'
/usr/bin/ld: /home/frank/Lib/Ada/Num/GSL/lib//libgsl.so: undefined reference to `gsl_odeiv2_step_bsimp'
/usr/bin/ld: /home/frank/Lib/Ada/Num/GSL/lib//libgsl.so: undefined reference to `gsl_odeiv2_step_rkf45'
/usr/bin/ld: /home/frank/Lib/Ada/Num/GSL/lib//libgsl.so: undefined reference to `gsl_odeiv2_step_rk1imp'
/usr/bin/ld: /home/frank/Lib/Ada/Num/GSL/lib//libgsl.so: undefined reference to `gsl_odeiv2_step_rk4'
/usr/bin/ld: /home/frank/Lib/Ada/Num/GSL/lib//libgsl.so: undefined reference to `gsl_odeiv2_driver_free'
/usr/bin/ld: /home/frank/Lib/Ada/Num/GSL/lib//libgsl.so: undefined reference to `gsl_strerror'
/usr/bin/ld: /home/frank/Lib/Ada/Num/GSL/lib//libgsl.so: undefined reference to `gsl_odeiv2_step_rkck'
/usr/bin/ld: /home/frank/Lib/Ada/Num/GSL/lib//libgsl.so: undefined reference to `gsl_odeiv2_step_msadams'
/usr/bin/ld: /home/frank/Lib/Ada/Num/GSL/lib//libgsl.so: undefined reference to `gsl_odeiv2_driver_alloc_y_new'
/usr/bin/ld: /home/frank/Lib/Ada/Num/GSL/lib//libgsl.so: undefined reference to `gsl_odeiv2_step_rk2imp'
/usr/bin/ld: /home/frank/Lib/Ada/Num/GSL/lib//libgsl.so: undefined reference to `gsl_integration_qng'
/usr/bin/ld: /home/frank/Lib/Ada/Num/GSL/lib//libgsl.so: undefined reference to `gsl_odeiv2_step_rk8pd'
/usr/bin/ld: /home/frank/Lib/Ada/Num/GSL/lib//libgsl.so: undefined reference to `gsl_odeiv2_step_rk2'
collect2: error: ld returned 1 exit status
gprbuild: link of test_odeiv2.adb failed
gprbuild: failed command was: /usr/bin/gnatgcc test_odeiv2.o b__test_odeiv2.o -L/home/frank/Lib/Ada/Num/GSL/lib/ -lgsl -L/home/frank/Lib/Ada/Num/GSL/Thin/lib/ -lgsl_thin_dyn -L/usr/lib/x86_64-linux-gnu -lgsl -lgslcblas -L/usr/lib/x86_64-linux-gnu -lgsl -lgslcblas -L/home/frank/Lib/Ada/Num/Tests/Test_GSL/obj_dyn/ -L/home/frank/Lib/Ada/Num/Tests/Test_GSL/obj_dyn/ -L/home/frank/Lib/Ada/Num/GSL/lib/ -L/home/frank/Lib/Ada/Num/GSL/Thin/lib/ -L/usr/lib/gcc/x86_64-linux-gnu/9/adalib/ -shared-libgcc -lgnarl-9 -lgnat-9 -lrt -lpthread -lrt -ldl -Wl,-rpath-link,/usr/lib/gcc/x86_64-linux-gnu/9//adalib -Wl,-z,origin,-rpath,$ORIGIN/../..//GSL/lib:$ORIGIN/../..//GSL/Thin/lib:/usr/lib/x86_64-linux-gnu:$ORIGIN//obj_dyn:/usr/lib/gcc/x86_64-linux-gnu/9/adalib:/usr/lib64:/usr/lib -o /home/frank/Lib/Ada/Num/Tests/Test_GSL//test_odeiv2_dyn

我错过了什么?

我的项目文件是:

1.

library project GSL_Thin_Dyn is

   version:= "1";

   for Source_Dirs use ("src", "src/matrix");
   for Library_Dir use "lib";
   for Object_Dir use "obj_rel";
   for Library_Name use "gsl_thin_dyn";
   for Library_Kind use "relocatable";
   for Library_Version use "libgsl_thin.so." & version;
   for Externally_Built use "false";

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

end GSL_Thin_Dyn;
with "Thin/gsl_thin_dyn";

library project GSL_dyn is

   version:= "1";
   
   for Source_Dirs use (".");
   for Object_Dir use "obj_dyn";
   for Library_Dir use "lib";
   for Library_Name use "gsl";
   for Library_Kind use "relocatable";
   for Library_Version use "libgsl.so." & version;
   for Externally_Built use "false";

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

end GSL_dyn;
with "../../../Gen/gen_shared";
with "../../GSL/Thin/gsl_thin_dyn";

project Test_Odeiv2_Thin_Dyn is

   for Source_Dirs use (".");
   case gen_shared.mode is
      when "debug"  => for Object_Dir use "obj_dyn";
      when "release"    => for Object_Dir use "obj_dyn/release";
      when others   => null;
   end case;
   for Exec_Dir use ".";
   for Main use ("test_odeiv2_thin.adb");

   package Builder is
      for Executable ("test_odeiv2_thin.adb") use "test_odeiv2_thin_dyn";
   end Builder;

end Test_Odeiv2_Thin_Dyn;
with "../../../Gen/gen_shared";
with "../../GSL/gsl_dyn";
        
project Test_Odeiv2_Dyn is
        
   for Source_Dirs use (".");
   case gen_shared.mode is
      when "debug"  => for Object_dir use "obj_dyn";
      when "release"    => for Object_Dir use "obj_dyn/release";
   end case;
   for Exec_Dir use ".";
   for Main use ("test_odeiv2.adb");
        
   package Linker is
      for Linker_Options use ("-L/usr/lib/x86_64-linux-gnu", "-lgsl", "-lgslcblas");
   end Linker;
    
   package Builder is
     for Executable ("test_odeiv2.adb") use "test_odeiv2_dyn";
   end Builder;
        
end Test_Odeiv2_Dyn;

您将厚包装器库命名为 gsl。您正在包装的库也被命名为 gsl。在内部,这将导致链接器获得 -lgsl 两次,并且两次都将解析为厚包装器。这就是为什么它缺少原始库中的符号的原因。

更改厚包装纸的 Library_Name 以解决此问题。