Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

static linking with gfortran

1,144 views
Skip to first unread message

Daniel Feenberg

unread,
Mar 3, 2020, 8:56:38 AM3/3/20
to
I want to send a working version of my program to a user at a government agency whose IT staff won't allow a fortran compiler (security concerns). The system is Linux and I am allowed to send binary executables(!).

foo.for compiles and executes fine but if I add the "-static" option:

gfortran -static foo.for

I get the following error messages and no a.out:

gfortran -static foo.for
/usr/bin/ld: cannot find -lm
/usr/bin/ld: cannot find -lm
/usr/bin/ld: cannot find -lc
collect2: error: ld returned 1 exit status

The compiler version is:

GNU Fortran (GCC) 4.8.5 20150623 (Red Hat 4.8.5-36)

If I omit "-static" the program compiles and runs correctly here, but complains that libquadmath.so.0 is missing at the user site. There is no possibility of cooperation from the user's IT staff. Is this relevant:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=46539

Years ago I was able to add -static and result worked fine here and at the user's site. Should I just get another compiler? I don't use quad precision, is it possible I could include some dummy routines for quad math in my source code? What would they be named?


Daniel Feenberg

Kay Diederichs

unread,
Mar 3, 2020, 9:49:08 AM3/3/20
to
what I suggest: replace the line

*lib: %{static-libgfortran:--as-needed} -lquadmath
%{static-libgfortran:--no-as-needed} -lm %(libgcc) %(liborig)

in /usr/lib/gcc/x86_64-redhat-linux/4.8.2/libgfortran.spec with

*lib: %{static-libgfortran:-Bstatic} -lquadmath
%{static-libgfortran:-Bdynamic} -lm %(libgcc) %(liborig)

and omit the -static, but use -static-libgfortran -static-libgcc when
linking.

HTH,
Kay

steve kargl

unread,
Mar 3, 2020, 10:11:47 AM3/3/20
to
Daniel Feenberg wrote:

> I want to send a working version of my program to a user at a government agency
> whose IT staff won't allow a fortran compiler (security concerns). The system is Linux
> and I am allowed to send binary executables(!).

This is a hoot. A Fortran compiler might be a security risk, but some random
executable from someone outside of the organization is acceptable.

>
> foo.for compiles and executes fine but if I add the "-static" option:
>
> gfortran -static foo.for
>
> I get the following error messages and no a.out:
>
> gfortran -static foo.for
> /usr/bin/ld: cannot find -lm
> /usr/bin/ld: cannot find -lm
> /usr/bin/ld: cannot find -lc
> collect2: error: ld returned 1 exit status

Well, do use have libm.a and libc.a installed on your system?

--
steve

Ev. Drikos

unread,
Mar 3, 2020, 3:19:36 PM3/3/20
to
On 03/03/2020 15:56, Daniel Feenberg wrote:
> ...
> The compiler version is:
>
> GNU Fortran (GCC) 4.8.5 20150623 (Red Hat 4.8.5-36)
>
> If I omit "-static" the program compiles and runs correctly here, but complains that libquadmath.so.0 is missing at the user site...

On my CentOS-7.6 box ie I see only the dynamic version of Quadmath:
/usr/lib64/libquadmath.so.0 (soft link)
/usr/lib64/libquadmath.so.0.0.0

It's my impression that for static linking a developer needs also:
/usr/lib64/libquadmath.a

The above should normally be available in "libquadmath-static*.rpm".
Not sure if this the problem though. Do you have statics installed?

Ev. Drikos

Kay Diederichs

unread,
Mar 5, 2020, 11:15:51 AM3/5/20
to
yes I should have mentioned that you need

yum -y install libquadmath-static

for this to work on on CentOS-7

Daniel Feenberg

unread,
Mar 8, 2020, 9:27:05 AM3/8/20
to
I followed these instructions, and this is the result:

sas1 taxsim: gcc -static-libgfortran -static-libgcc hello.o
hello.o: In function `MAIN__':
hello.for:(.text+0x3f): undefined reference to `_gfortran_st_write'
hello.for:(.text+0x58): undefined reference to `_gfortran_transfer_character_write'
hello.for:(.text+0x67): undefined reference to `_gfortran_st_write_done'
hello.for:(.text+0x76): undefined reference to `_gfortran_stop_string'
hello.o: In function `main':
hello.for:(.text+0x96): undefined reference to `_gfortran_set_args'
hello.for:(.text+0xa5): undefined reference to `_gfortran_set_options'
collect2: error: ld returned 1 exit status

I take it there is at least one more library I need to specify.

It seems like libquadmath has been the cause of this known "won't fix" since 2010:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=46539

althugh a patch was proposed in 2014:

https://gcc.gnu.org/ml/gcc-patches/2014-10/msg00375.html

Note sure what the motivation is for keeping it this way. The argument here:

https://gcc.gnu.org/ml/fortran/2010-11/msg00273.html

that libquadmath is LGPL and gcc is GPL doesn't seem to make sense to me - surely the result of binding them together is GPL because that is the most restrictive license.

Daniel Feenberg

Thomas Koenig

unread,
Mar 8, 2020, 9:37:00 AM3/8/20
to
Daniel Feenberg <feen...@gmail.com> schrieb:

> sas1 taxsim: gcc -static-libgfortran -static-libgcc hello.o
> hello.o: In function `MAIN__':
> hello.for:(.text+0x3f): undefined reference to `_gfortran_st_write'

Try using "gfortran" to do the linking (or specify libgfortran
explicitly).
0 new messages