public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* gfortran -static on MACs
       [not found] <da765f0e461543fc93eccb142b41f308@ITDSRVMBX000.utep.edu>
@ 2018-02-10 13:40 ` Sewell, Granville
  2018-02-10 19:45   ` Manfred Schwarb
  0 siblings, 1 reply; 5+ messages in thread
From: Sewell, Granville @ 2018-02-10 13:40 UTC (permalink / raw)
  To: fortran


The Linux and Windows versions of Gfortran work with

  gfortran -static  -o prog.exe prog.f

to produce an executable that can be run on other systems where gfortran is not installed.

But the -static option does not seem to work with gfortran on a MAC, I get
   ld: library not found for -lcrt0.o
and another person with a different version of gfortran on his MAC gets the same results.

 gfortran -static-libgfortran prog.f

works, but the executable does not even seem to run on other systems with a different version of gfortran.

So it seems to be impossible to produce any executable with gfortran  on a MAC that has the dynamic libraries loaded
so it can run elsewhere.

Is there a way to get -static to work on MACs, or any other way to produce a portable executable?

Thanks for your help

Granville Sewell

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

* Re: gfortran -static on MACs
  2018-02-10 13:40 ` gfortran -static on MACs Sewell, Granville
@ 2018-02-10 19:45   ` Manfred Schwarb
  2018-02-12 20:12     ` Janus Weil
  0 siblings, 1 reply; 5+ messages in thread
From: Manfred Schwarb @ 2018-02-10 19:45 UTC (permalink / raw)
  To: Sewell, Granville, fortran

Am 10.02.2018 um 14:40 schrieb Sewell, Granville:
> 
> The Linux and Windows versions of Gfortran work with
> 
>   gfortran -static  -o prog.exe prog.f
> 
> to produce an executable that can be run on other systems where gfortran is not installed.
> 
> But the -static option does not seem to work with gfortran on a MAC, I get
>    ld: library not found for -lcrt0.o
> and another person with a different version of gfortran on his MAC gets the same results.
> 
>  gfortran -static-libgfortran prog.f
> 
> works, but the executable does not even seem to run on other systems with a different version of gfortran.
> 

probably the following patch will help somewhat. You have to patch all files named
"libgfortran.spec" in the path of your _installed_ compiler. With this change
"-static-libgfortran" will imply static linking to libquadmath.

--- libgfortran.spec.old        2017-05-29 21:46:01.036867084 +0000
+++ libgfortran.spec    2017-08-08 12:04:01.500558409 +0000
@@ -5,4 +5,4 @@
 #

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


HTH,
Manfred


> So it seems to be impossible to produce any executable with gfortran  on a MAC that has the dynamic libraries loaded
> so it can run elsewhere.
> 
> Is there a way to get -static to work on MACs, or any other way to produce a portable executable?
> 
> Thanks for your help
> 
> Granville Sewell
> 

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

* Re: gfortran -static on MACs
  2018-02-10 19:45   ` Manfred Schwarb
@ 2018-02-12 20:12     ` Janus Weil
       [not found]       ` <70d853eea5aa46e5b2410afece89c43a@ITDSRVMBX000.utep.edu>
  0 siblings, 1 reply; 5+ messages in thread
From: Janus Weil @ 2018-02-12 20:12 UTC (permalink / raw)
  To: Manfred Schwarb; +Cc: Sewell, Granville, fortran

> Am 10.02.2018 um 14:40 schrieb Sewell, Granville:
>>
>> The Linux and Windows versions of Gfortran work with
>>
>>   gfortran -static  -o prog.exe prog.f
>>
>> to produce an executable that can be run on other systems where gfortran is not installed.
>>
>> But the -static option does not seem to work with gfortran on a MAC, I get
>>    ld: library not found for -lcrt0.o
>> and another person with a different version of gfortran on his MAC gets the same results.

Statically linked executables are not supported on Mac OS, see:
https://developer.apple.com/library/content/qa/qa1118/_index.html



>>  gfortran -static-libgfortran prog.f
>>
>> works, but the executable does not even seem to run on other systems with a different version of gfortran.
>>
>
> probably the following patch will help somewhat. You have to patch all files named
> "libgfortran.spec" in the path of your _installed_ compiler. With this change
> "-static-libgfortran" will imply static linking to libquadmath.
>
> --- libgfortran.spec.old        2017-05-29 21:46:01.036867084 +0000
> +++ libgfortran.spec    2017-08-08 12:04:01.500558409 +0000
> @@ -5,4 +5,4 @@
>  #
>
>  %rename lib liborig
> -*lib: %{static-libgfortran:--as-needed} -lquadmath %{static-libgfortran:--no-as-needed} -lm %(libgcc) %(liborig)
> +*lib: %{static-libgfortran:-Bstatic} -lquadmath %{static-libgfortran:-Bdynamic} -lm %(libgcc) %(liborig


A -static-libquadmath flag has been proposed in the past, but
apparently the patch has never been committed:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=46539

Would certainly be good to have this.

Cheers,
Janus

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

* Re: gfortran -static on MACs
       [not found]       ` <70d853eea5aa46e5b2410afece89c43a@ITDSRVMBX000.utep.edu>
@ 2018-02-12 23:10         ` Manfred Schwarb
  2018-02-13 19:55           ` Janus Weil
  0 siblings, 1 reply; 5+ messages in thread
From: Manfred Schwarb @ 2018-02-12 23:10 UTC (permalink / raw)
  To: Sewell, Granville, fortran

Sewell,

Am 12.02.2018 um 22:43 schrieb Sewell, Granville:
> Janus and Manfred,
> 
> As you can tell, I'm a bit ignorant, don't understand very well even the difference between static and dynamic libraries,
> but from the developer.apple.com link you gave me it appears that static-linked binaries are simply not supported on MAC OSX;
> if that is the case, what is the point of the patches to libgfortran.spec suggested by Manfred, and other users in the
> link Janus sent me, I thought that was precisely to help me create a static-linked binary.   Obviously I am missing something
> important.   Bottom line is I simple want to create an executable from my Fortran program that people on other MAC OSX
> systems can run without having gfortran installed.   If that is really impossible, I'd at least like to create an executable
> that will work on MAC OSX systems where a different version of gfortran is installed.   But I haven't had any success even
> with this, I created an executable using "gfortran -static-libgfortran -o prog.exe  prog.f"   but when a user tries to run
> it on a system with an earlier version of gfortran installed, they get "libquadmath.dylib not found" (approximately).   
> 

No, fully static linkage (static binary) seems not to work on Mac OSX. I thought that partial static linking 
does work on OSX, thus my provided patch.
The thing is, portability-wise core c-libraries are normally less problematic than the 
gfortran and quadmath libraries, so the idea was to only statically compile in these more 
volatile libraries. But I was wrong, the OSX linker is not clever
enough for this, you can't switch between static and dynamic within a single link command
(And the GNU linker seems not to work on OSX, you have to use the system linker).

The only thing that seems to work is to link to static libraries by means of indicating the full path
to the static libraries, i.e.
  ld mymainprogram.dylib /usr/local/lib/mylibrary.a -o mymainprogram.exe

or, when the compiler invokes the linker:
  gfortran mymainprogram.f /usr/local/lib/mylibrary.a -o mymainprogram.exe

So for OSX, I think you are mostly out of luck, I guess.

You could try to change your libgfortran.spec to read
  *lib: /my/path/to/libquadmath.a -lm %(libgcc) %(liborig)
as last line, but I'm a bit pessimistic.

Cheers,
Manfred


> Thanks for you patience.
> 
> Granville
> ________________________________________
> From: jaydub66@gmail.com [jaydub66@gmail.com] on behalf of Janus Weil [janus@gcc.gnu.org]
> Sent: Monday, February 12, 2018 1:12 PM
> To: Manfred Schwarb
> Cc: Sewell, Granville; fortran@gcc.gnu.org
> Subject: Re: gfortran -static on MACs
> 
>> Am 10.02.2018 um 14:40 schrieb Sewell, Granville:
>>>
>>> The Linux and Windows versions of Gfortran work with
>>>
>>>   gfortran -static  -o prog.exe prog.f
>>>
>>> to produce an executable that can be run on other systems where gfortran is not installed.
>>>
>>> But the -static option does not seem to work with gfortran on a MAC, I get
>>>    ld: library not found for -lcrt0.o
>>> and another person with a different version of gfortran on his MAC gets the same results.
> 
> Statically linked executables are not supported on Mac OS, see:
> https://developer.apple.com/library/content/qa/qa1118/_index.html
> 
> 
> 
>>>  gfortran -static-libgfortran prog.f
>>>
>>> works, but the executable does not even seem to run on other systems with a different version of gfortran.
>>>
>>
>> probably the following patch will help somewhat. You have to patch all files named
>> "libgfortran.spec" in the path of your _installed_ compiler. With this change
>> "-static-libgfortran" will imply static linking to libquadmath.
>>
>> --- libgfortran.spec.old        2017-05-29 21:46:01.036867084 +0000
>> +++ libgfortran.spec    2017-08-08 12:04:01.500558409 +0000
>> @@ -5,4 +5,4 @@
>>  #
>>
>>  %rename lib liborig
>> -*lib: %{static-libgfortran:--as-needed} -lquadmath %{static-libgfortran:--no-as-needed} -lm %(libgcc) %(liborig)
>> +*lib: %{static-libgfortran:-Bstatic} -lquadmath %{static-libgfortran:-Bdynamic} -lm %(libgcc) %(liborig
> 
> 
> A -static-libquadmath flag has been proposed in the past, but
> apparently the patch has never been committed:
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=46539
> 
> Would certainly be good to have this.
> 
> Cheers,
> Janus
> 

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

* Re: gfortran -static on MACs
  2018-02-12 23:10         ` Manfred Schwarb
@ 2018-02-13 19:55           ` Janus Weil
  0 siblings, 0 replies; 5+ messages in thread
From: Janus Weil @ 2018-02-13 19:55 UTC (permalink / raw)
  To: Manfred Schwarb, Francois Xavier Coudert; +Cc: Sewell, Granville, fortran

Dear Sewell,

>> Bottom line is I simple want to create an executable from my Fortran program that people on other MAC OSX
>> systems can run without having gfortran installed.   If that is really impossible

I don't think it's impossible. That is basically what
-static-libgfortran is for, which in principle seems to work for you.
Problem is, it's not complete in a sense: It links your program to the
static version of libgfortran, but still uses a dynamic libquadmath.

I think the cleanest solution to this problem is to add a
-static-libquadmath flag to gfortran, as proposed in PR 46539. Maybe
we can get FX to dust off his old patch for this PR and make it fit
for GCC 9?

(Btw, a quick fix for you might be to simply distribute libquadmath.so
together with your application.)

Cheers,
Janus




>> Sent: Monday, February 12, 2018 1:12 PM
>> To: Manfred Schwarb
>> Cc: Sewell, Granville; fortran@gcc.gnu.org
>> Subject: Re: gfortran -static on MACs
>>
>>> Am 10.02.2018 um 14:40 schrieb Sewell, Granville:
>>>>
>>>> The Linux and Windows versions of Gfortran work with
>>>>
>>>>   gfortran -static  -o prog.exe prog.f
>>>>
>>>> to produce an executable that can be run on other systems where gfortran is not installed.
>>>>
>>>> But the -static option does not seem to work with gfortran on a MAC, I get
>>>>    ld: library not found for -lcrt0.o
>>>> and another person with a different version of gfortran on his MAC gets the same results.
>>
>> Statically linked executables are not supported on Mac OS, see:
>> https://developer.apple.com/library/content/qa/qa1118/_index.html
>>
>>
>>
>>>>  gfortran -static-libgfortran prog.f
>>>>
>>>> works, but the executable does not even seem to run on other systems with a different version of gfortran.
>>>>
>>>
>>> probably the following patch will help somewhat. You have to patch all files named
>>> "libgfortran.spec" in the path of your _installed_ compiler. With this change
>>> "-static-libgfortran" will imply static linking to libquadmath.
>>>
>>> --- libgfortran.spec.old        2017-05-29 21:46:01.036867084 +0000
>>> +++ libgfortran.spec    2017-08-08 12:04:01.500558409 +0000
>>> @@ -5,4 +5,4 @@
>>>  #
>>>
>>>  %rename lib liborig
>>> -*lib: %{static-libgfortran:--as-needed} -lquadmath %{static-libgfortran:--no-as-needed} -lm %(libgcc) %(liborig)
>>> +*lib: %{static-libgfortran:-Bstatic} -lquadmath %{static-libgfortran:-Bdynamic} -lm %(libgcc) %(liborig
>>
>>
>> A -static-libquadmath flag has been proposed in the past, but
>> apparently the patch has never been committed:
>> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=46539
>>
>> Would certainly be good to have this.
>>
>> Cheers,
>> Janus
>>
>

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

end of thread, other threads:[~2018-02-13 19:55 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <da765f0e461543fc93eccb142b41f308@ITDSRVMBX000.utep.edu>
2018-02-10 13:40 ` gfortran -static on MACs Sewell, Granville
2018-02-10 19:45   ` Manfred Schwarb
2018-02-12 20:12     ` Janus Weil
     [not found]       ` <70d853eea5aa46e5b2410afece89c43a@ITDSRVMBX000.utep.edu>
2018-02-12 23:10         ` Manfred Schwarb
2018-02-13 19:55           ` Janus Weil

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).