【问题标题】:libtool don't compile Fortran to shared librarylibtool 不将 Fortran 编译为共享库
【发布时间】:2014-03-21 10:22:31
【问题描述】:

我需要使用 libtool 编译 Fortran 库,因为我需要静态和共享版本,但编译方式与 C 库不同。

如果是 C 库:

$ cat hello.c 
#include <stdio.h>

int hello() {
  printf("Hello\n");
  return 0;
}
$ libtool --tag=CC --mode=compile gcc -c hello.c
libtool: compile:  gcc -c hello.c  -fPIC -DPIC -o .libs/hello.o
libtool: compile:  gcc -c hello.c -o hello.o >/dev/null 2>&1
$ nm .libs/hello.o              
                 U _GLOBAL_OFFSET_TABLE_
0000000000000000 T hello
                 U puts

正如您在上面的示例中看到的那样,libtool 添加了-fPIC,而对象添加了_GLOBAL_OFFSET_TABLE_

对于 Fortran 库:

$ cat hello.f 
        function hello ()
            write (*,*) "Hello"
        endfunction hello
$ libtool --tag=FC --mode=compile gfortran -c hello.f
libtool: compile:  gfortran -c hello.f  -o .libs/hello.o
libtool: compile:  gfortran -c hello.f >/dev/null 2>&1
$ nm .libs/hello.o 
                 U _gfortran_st_write
                 U _gfortran_st_write_done
                 U _gfortran_transfer_character_write
0000000000000000 T hello_

正如您在上面的示例中看到的那样,libtool 没有添加-fPIC,并且对象没有添加_GLOBAL_OFFSET_TABLE_

我该如何解决这个问题?

其他信息

$ libtool --version
libtool (GNU libtool) 2.4.2
$ gcc --version
gcc (GCC) 4.8.2 20140206 (prerelease)
$ gfortran --version
GNU Fortran (GCC) 4.8.2 20140206 (prerelease)

【问题讨论】:

    标签: fortran shared-libraries libtool


    【解决方案1】:

    你也可以只使用gcc

    > libtool --tag=FC --mode=compile gcc -c hello.f90
    libtool: compile:  gcc -c hello.f90  -fPIC -o .libs/hello.o
    libtool: compile:  gcc -c hello.f90 -o hello.o >/dev/null 2>&1
    > nm .libs/hello.o
                     U _gfortran_st_write
                     U _gfortran_st_write_done
                     U _gfortran_transfer_character_write
                     U _GLOBAL_OFFSET_TABLE_
    0000000000000000 T hello_
    

    【讨论】:

      猜你喜欢
      • 2011-07-31
      • 1970-01-01
      • 2012-12-31
      • 2013-03-30
      • 1970-01-01
      • 2023-03-11
      • 2013-03-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多