public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* (no subject)
@ 2021-03-19 20:22 Daniel Feenberg
  2021-03-19 20:49 ` gfortran static linking under OS X (was: Re: ) Tobias Burnus
  0 siblings, 1 reply; 8+ messages in thread
From: Daniel Feenberg @ 2021-03-19 20:22 UTC (permalink / raw)
  To: fortran

Is there a way to make a statically linked binary with fortran in OS
X? For much of the past year I have been using:

     gfortran taxsim.for -static-libgfortran -static-libgcc

but since January I only get the error message;

     ld: library not found for -lm.
     collect2: error: ld returned 1 exit status?

This is OS X 11,2,3 Big Sur and fortran version 6.3.0. I need static
linking because my users are not developers and do not have Xcode or
gcc installed. This is free software.  I have seen postings from 2015
suggesting that I rename libquadmath.0.dylib, which I did try but
which did not help.

Of course I have no need for lquad precision variables, which I
understand is the source of the problem.

Daniel Feenberg
NBER

^ permalink raw reply	[flat|nested] 8+ messages in thread

* gfortran static linking under OS X (was: Re: )
  2021-03-19 20:22 Daniel Feenberg
@ 2021-03-19 20:49 ` Tobias Burnus
  2021-03-19 21:06   ` Iain Sandoe
  2021-03-19 22:11   ` Daniel Feenberg
  0 siblings, 2 replies; 8+ messages in thread
From: Tobias Burnus @ 2021-03-19 20:49 UTC (permalink / raw)
  To: feenberg, fortran; +Cc: Daniel Feenberg

Hi,

I am not sure whether it helps, but I want to point out that libm is the 
math library which is on Linux usually GLIBC and I assume on OS X it is 
provided by the OS vendor.

Additionally, that libm is linked dynamically.

This seems to be a OS X issue – and I have no idea about OS X, but I 
found the following:

https://github.com/fxcoudert/gfortran-for-macOS/issues/12

which suggests that there is a mismatch of the XCode / MacOS X SDK version.

As work around, it seems to work to set MACOSX_DEPLOYMENT_TARGET and/or 
to ensure that you have the same xcode version as the one used by 
gfortran, e.g. by "xcode-select --install".

In some other thread, the suggestion was to use -L/usr/lib but I assume 
that won't help. Looking at 
https://github.com/xianyi/OpenBLAS/issues/3032 – it seems as if you can 
use 'gfortran -v taxsim.for' to see the SDK version used when building GCC.

At least that example had some |string like:
||-syslibroot /Library/Developer/CommandLineTools/SDKs/MacOSX11.1.sdk/|

|If you had installed 11.0 instead, ||MACOSX_DEPLOYMENT_TARGET=11.0 
would work.|

|I hope it helps. If not, you need to find someone else as I have no 
idea about OS X.|

|Good luck!|

|Tobias
|

On 19.03.21 21:22, Daniel Feenberg via Fortran wrote:

> Is there a way to make a statically linked binary with fortran in OS
> X? For much of the past year I have been using:
>
>       gfortran taxsim.for -static-libgfortran -static-libgcc
>
> but since January I only get the error message;
>
>       ld: library not found for -lm.
>       collect2: error: ld returned 1 exit status?
>
> This is OS X 11,2,3 Big Sur and fortran version 6.3.0. I need static
> linking because my users are not developers and do not have Xcode or
> gcc installed. This is free software.  I have seen postings from 2015
> suggesting that I rename libquadmath.0.dylib, which I did try but
> which did not help.
>
> Of course I have no need for lquad precision variables, which I
> understand is the source of the problem.
>
> Daniel Feenberg
> NBER

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: gfortran static linking under OS X (was: Re: )
  2021-03-19 20:49 ` gfortran static linking under OS X (was: Re: ) Tobias Burnus
@ 2021-03-19 21:06   ` Iain Sandoe
  2021-03-19 22:11   ` Daniel Feenberg
  1 sibling, 0 replies; 8+ messages in thread
From: Iain Sandoe @ 2021-03-19 21:06 UTC (permalink / raw)
  To: Daniel Feenberg; +Cc: feenberg, Fortran List, Tobias Burnus

Hi Daniel,

Tobias Burnus <burnus@net-b.de> wrote:

> I am not sure whether it helps, but I want to point out that libm is the  
> math library which is on Linux usually GLIBC and I assume on OS X it is  
> provided by the OS vendor.

actually part of libSystem  (but, yes, provided by the vendor)

> On 19.03.21 21:22, Daniel Feenberg via Fortran wrote:
>
>> Is there a way to make a statically linked binary with fortran in OS
>> X? For much of the past year I have been using:
>>
>>      gfortran taxsim.for -static-libgfortran -static-libgcc

OK - that should work - modulo the quadmath issue (if present) -
.. but that is probably solvable (with some changes to the link spec).

>> but since January I only get the error message;
>>
>>      ld: library not found for -lm.
>>      collect2: error: ld returned 1 exit status?

lm has not been needed on macOS for a [very] long time (for many releases  
it was simply a convenience symlink to libSystem.dylib, for the sake of OSS  
code that appends ‘-lm’).

There doesn’t seem to be an issue with gcc-11 (master, development) or  
10.2.1 (upcoming 10.3) on macOS 11 - will see if I can fire up a copy of  
gcc6.5 there ...

Will have a think about how to fake the libm too .. not so easy these days.

>> This is OS X 11,2,3 Big Sur and fortran version 6.3.0.

This is an old version of Fortran on a very new version of macOS, at  
present the first supported GCC version for macOS 11 is the upcoming 10.3  
release (although homebrew no doubt has a preview courtesy of FX).

Is there any way you would be able to update to a newer (and eventually  
supported) Fortran version ?

>> I need static
>> linking because my users are not developers and do not have Xcode or
>> gcc installed.

understood.

>> This is free software.  I have seen postings from 2015
>> suggesting that I rename libquadmath.0.dylib, which I did try but
>> which did not help.
>>
>> Of course I have no need for lquad precision variables, which I
>> understand is the source of the problem.

not from what you posted - it’s the absence of “libm.dylib” that results in  
the message.

I realise that this mail contains no solutions - but will try to reproduce  
the issue over the weekend.

cheers
Iain


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: gfortran static linking under OS X (was: Re: )
  2021-03-19 20:49 ` gfortran static linking under OS X (was: Re: ) Tobias Burnus
  2021-03-19 21:06   ` Iain Sandoe
@ 2021-03-19 22:11   ` Daniel Feenberg
  2021-03-19 22:39     ` Iain Sandoe
  1 sibling, 1 reply; 8+ messages in thread
From: Daniel Feenberg @ 2021-03-19 22:11 UTC (permalink / raw)
  To: Tobias Burnus; +Cc: fortran, Daniel Feenberg



On Fri, 19 Mar 2021, Tobias Burnus wrote:

> Hi,
>
> I am not sure whether it helps, but I want to point out that libm is the math 
> library which is on Linux usually GLIBC and I assume on OS X it is provided 
> by the OS vendor.
>
> Additionally, that libm is linked dynamically.
>
> This seems to be a OS X issue ? and I have no idea about OS X, but I found 
> the following:
>
> https://github.com/fxcoudert/gfortran-for-macOS/issues/12
>

It is certainly an OS X issue. There is no problem in Linux, FreeBSD or 
Windows with the same compiler. As I understand it, OS X doesn't allow 
true dynamic linking, but it does allow a compiler/linker to produce an 
executable binary which only requires OS supplied libraries at execution 
time, and which includes all the compiler specific libraries. So I 
wouldn't actually expect libm to be statically linked.

Apparently the problem arises because the authors of libquadm don't want 
users to use it in statically linked binaries, and did something to 
prevent that from happening. Unfortunately, it means that specialized 
knowledge is required to statically link gfortran programs, even if they 
don't use quad precision math.

Daniel Feenberg

> which suggests that there is a mismatch of the XCode / MacOS X SDK version.
>
> As work around, it seems to work to set MACOSX_DEPLOYMENT_TARGET and/or to 
> ensure that you have the same xcode version as the one used by gfortran, e.g. 
> by "xcode-select --install".
>
> In some other thread, the suggestion was to use -L/usr/lib but I assume that 
> won't help. Looking at https://github.com/xianyi/OpenBLAS/issues/3032 ? it 
> seems as if you can use 'gfortran -v taxsim.for' to see the SDK version used 
> when building GCC.
>
> At least that example had some |string like:
> ||-syslibroot /Library/Developer/CommandLineTools/SDKs/MacOSX11.1.sdk/|
>
> |If you had installed 11.0 instead, ||MACOSX_DEPLOYMENT_TARGET=11.0 would 
> work.|
>
> |I hope it helps. If not, you need to find someone else as I have no idea 
> about OS X.|
>
> |Good luck!|
>
> |Tobias
> |
>
> On 19.03.21 21:22, Daniel Feenberg via Fortran wrote:
>
>> Is there a way to make a statically linked binary with fortran in OS
>> X? For much of the past year I have been using:
>>
>>       gfortran taxsim.for -static-libgfortran -static-libgcc
>> 
>> but since January I only get the error message;
>>
>>       ld: library not found for -lm.
>>       collect2: error: ld returned 1 exit status?
>> 
>> This is OS X 11,2,3 Big Sur and fortran version 6.3.0. I need static
>> linking because my users are not developers and do not have Xcode or
>> gcc installed. This is free software.  I have seen postings from 2015
>> suggesting that I rename libquadmath.0.dylib, which I did try but
>> which did not help.
>> 
>> Of course I have no need for lquad precision variables, which I
>> understand is the source of the problem.
>> 
>> Daniel Feenberg
>> NBER
>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: gfortran static linking under OS X (was: Re: )
  2021-03-19 22:11   ` Daniel Feenberg
@ 2021-03-19 22:39     ` Iain Sandoe
  2021-03-20 20:47       ` Daniel Feenberg
  0 siblings, 1 reply; 8+ messages in thread
From: Iain Sandoe @ 2021-03-19 22:39 UTC (permalink / raw)
  To: Daniel Feenberg; +Cc: Tobias Burnus, Daniel Feenberg, Fortran List

Daniel Feenberg <feenberg@nber.org> wrote:

>
>
> On Fri, 19 Mar 2021, Tobias Burnus wrote:
>

>> This seems to be a OS X issue ? and I have no idea about OS X, but I  
>> found the following:
>>
>> https://github.com/fxcoudert/gfortran-for-macOS/issues/12
>
> It is certainly an OS X issue.

Actually, it’s a gfortran issue.

> There is no problem in Linux, FreeBSD or Windows with the same compiler.
> As I understand it, OS X doesn't allow true dynamic linking, but it does  
> allow a compiler/linker to produce an executable binary which only  
> requires OS supplied libraries at execution time, and which includes all  
> the compiler specific libraries.

OSX doesn’t allow a completely  statically-linked user space application.

but it does allow libgfortran and libquadmath to be statically linked - the  
issue is that there’s no spec to deal with it.
>
> Apparently the problem arises because the authors of libquadm don't want  
> users to use it in statically linked binaries,

no such issue, there is a static libquadmath.a installed ...

====

you should be able to work around this without changing the compiler or  
rebuilding it,

find

/path/to/compiler/install/lib/libgfortran.spec

make a copy of that (for backup only)

the file contains something like:

#
# This spec file is read by gfortran when linking.
# It is used to specify the libraries we need to link in, in the right
# order.
#

%rename lib liborig
*lib:  -lquadmath -lm %(libgcc) %(liborig)

change the last line line to :

*lib: %{!static-libgfortran: -lquadmath } %{static-libgfortran:  
libquadmath.a%s} %(libgcc) %(liborig)

===

and try your link again

look at the linked object with “otool -Lv executable” and you should see  
that it only refers to libSystem.dylib.


HTH
Iain


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: gfortran static linking under OS X (was: Re: )
  2021-03-19 22:39     ` Iain Sandoe
@ 2021-03-20 20:47       ` Daniel Feenberg
  2021-03-20 21:07         ` Iain Sandoe
  0 siblings, 1 reply; 8+ messages in thread
From: Daniel Feenberg @ 2021-03-20 20:47 UTC (permalink / raw)
  To: Iain Sandoe; +Cc: Tobias Burnus, Fortran List

On 3/19/21, Iain Sandoe <idsandoe@googlemail.com> wrote:

>> On Fri, 19 Mar 2021, Tobias Burnus wrote:

>
> you should be able to work around this without changing the compiler or
> rebuilding it,
>
> find
>
> /path/to/compiler/install/lib/libgfortran.spec
>
> make a copy of that (for backup only)
>
> the file contains something like:
>
> #
> # This spec file is read by gfortran when linking.
> # It is used to specify the libraries we need to link in, in the right
> # order.
> #
>
> %rename lib liborig
> *lib:  -lquadmath -lm %(libgcc) %(liborig)
>
> change the last line line to :
>
> *lib: %{!static-libgfortran: -lquadmath } %{static-libgfortran:
> libquadmath.a%s} %(libgcc) %(liborig)
>
> ===
>
> and try your link again
>

Tried that, the error message is:

   ld: library not found for -lSystem

Indeed there is no libsystem.a anywhere on the computer. Any ideas?

Daniel Feenberg

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: gfortran static linking under OS X (was: Re: )
  2021-03-20 20:47       ` Daniel Feenberg
@ 2021-03-20 21:07         ` Iain Sandoe
  2021-03-22 22:20           ` Daniel Feenberg
  0 siblings, 1 reply; 8+ messages in thread
From: Iain Sandoe @ 2021-03-20 21:07 UTC (permalink / raw)
  To: feenberg; +Cc: Fortran List

Daniel Feenberg <feenberg@gmail.com> wrote:

> On 3/19/21, Iain Sandoe <idsandoe@googlemail.com> wrote:
>
>>> On Fri, 19 Mar 2021, Tobias Burnus wrote:
>
>> you should be able to work around this without changing the compiler or
>> rebuilding it,

>> %rename lib liborig
>> *lib:  -lquadmath -lm %(libgcc) %(liborig)
>>
>> change the last line line to :
>>
>> *lib: %{!static-libgfortran: -lquadmath } %{static-libgfortran:
>> libquadmath.a%s} %(libgcc) %(liborig)

^^ this line is presumably not broken in your file - i.e. this is a mailer
phenomenon?

>> ===
>>
>> and try your link again
>
> Tried that, the error message is:
>
>   ld: library not found for -lSystem

Please could you either file a PR or send the output of

/your complete command line/ with ‘-save-temps -v’ appended

to me off-list.

----

For the record, this was not completely theoretical on my part; I actually  
tried this on a macOS 11.2.3 system with gcc-6.5 (which is the closest I  
have to what you’re using)

…./gcc-6-5/bin/gfortran /source/test/fortran/hello.f -static-libgfortran  
-static-libgcc -o h

$  otool -Lv h
h:
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1292.60.1)
	time stamp 2 Thu Jan  1 01:00:02 1970

This ^^ is what I expect to see;
libgfortran, libquadmath and libgcc have all been linked statically,  
leaving only
the "/usr/lib/libSystem.B.dylib” which is fine and expected.

> Indeed there is no libsystem.a anywhere on the computer.

macOS does not allow the equivalent of a “completely statically linked”  
user-mode
executable.  Exes are always started by “dyld” (dynamic linker) and they  
always refer
to libSystem.dylib.

So you should never be needing to find a libSystem.a (there isn’t one, as  
you found).
Nor do you need to care about it - since it’s available to all your  
end-users as part
of their system (as are things like the Accelerate framework).

> Any ideas?

I am somewhat surprised that 6.3 behaves any differently from 6.5 - let’s  
investigate a little more.

cheers
Iain


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: gfortran static linking under OS X (was: Re: )
  2021-03-20 21:07         ` Iain Sandoe
@ 2021-03-22 22:20           ` Daniel Feenberg
  0 siblings, 0 replies; 8+ messages in thread
From: Daniel Feenberg @ 2021-03-22 22:20 UTC (permalink / raw)
  To: Iain Sandoe; +Cc: Fortran List



On Sat, 20 Mar 2021, Iain Sandoe wrote:

> Daniel Feenberg <feenberg@gmail.com> wrote:
>
>> On 3/19/21, Iain Sandoe <idsandoe@googlemail.com> wrote:
>> 
>>>> On Fri, 19 Mar 2021, Tobias Burnus wrote:
>> 
>>> you should be able to work around this without changing the compiler or
>>> rebuilding it,
>
>>> %rename lib liborig
>>> *lib:  -lquadmath -lm %(libgcc) %(liborig)

...
>

I managed to install 10.2 and found that the error message goes away. No 
need to mess with the .spec file.A "static" binary can be produced with:

    gfortran taxsim.for -static-libgfortran -static-libgcc

in version 10.2. however, I have only one Mac, so I can't be 100% sure the 
binary will port to another machine, but I am hopeful.

Thank you all for your attention..

Daniel Feenberg
NBER

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-03-22 22:20 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-19 20:22 Daniel Feenberg
2021-03-19 20:49 ` gfortran static linking under OS X (was: Re: ) Tobias Burnus
2021-03-19 21:06   ` Iain Sandoe
2021-03-19 22:11   ` Daniel Feenberg
2021-03-19 22:39     ` Iain Sandoe
2021-03-20 20:47       ` Daniel Feenberg
2021-03-20 21:07         ` Iain Sandoe
2021-03-22 22:20           ` Daniel Feenberg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).