Question

I need to use libtool to compile a Fortran library, because I need the static and shared version, but the compilation won't work in the same way of a C library.

In the case of a C library:

$ 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

As you can see in the example above libtool has add the -fPIC and the object has the _GLOBAL_OFFSET_TABLE_.

In the case of a Fortran library:

$ 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_

As you can see in the example above libtool hasn't add the -fPIC and the object hasn't the _GLOBAL_OFFSET_TABLE_.

How can I solve this problem?

Additional information

$ 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)
Was it helpful?

Solution

You can also just use 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_
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top