executing gcc9 on macOS 10.14

Chris Jones jonesc at hep.phy.cam.ac.uk
Wed Oct 23 08:34:43 UTC 2019


Hi,

I forgot one detail from the recent fix to gcc to enable it to find 
system libraries.

What the fix did was add a patch to allow gcc9 to find the SDK in the 
same way as clang. This means either you use xcrun to run the command, 
or set the XDKROOT variable. See

<https://github.com/macports/macports-ports/commit/1850136d289019f3b29a5b24d3ec8ef9b23913ee#diff-bf5951877cf7f70968394fcc87aa5721>

https://gcc.gnu.org/ml/gcc-patches/2019-10/msg00251.html

for more info.

So. You need to either run gcc through xcrun, i.e.

  > xcrun gfortran-mp-9 -o test.exe ./test.f

or (as I use) set

export SDKROOT=`xcrun --show-sdk-path`

I actually had set the above in my shell profile, so I always have it, 
which is why gfortran worked for me 'out the box' (and thus I forgot it 
was there, which was my original intention....)

Chris

On 22/10/2019 6:09 pm, Chris Jones wrote:
> Hi,
> 
> Your ld command is incomplete. You aren't passing any of the runtime 
> libraries needed to link the .o file into an executable.
> 
> The simplest approach is to let gcc do the full job.
> 
> Titan ~/Documents/Code > cat test.f
>        program hello
>            print *, "Hello World!"
>        end program hello
> Titan ~/Documents/Code > gfortran-mp-9 -o test.exe ./test.f
> Titan ~/Documents/Code > ./test.exe
>   Hello World!
> 
> Titan ~/Documents/Code > otool -L ./test.exe
> ./test.exe:
>      /opt/local/lib/libgcc/libgfortran.5.dylib (compatibility version 
> 6.0.0, current version 6.0.0)
>      /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current 
> version 1252.200.5)
>      /opt/local/lib/libgcc/libgcc_s.1.dylib (compatibility version 
> 1.0.0, current version 1.0.0)
>      /opt/local/lib/libgcc/libquadmath.0.dylib (compatibility version 
> 1.0.0, current version 1.0.0)
> 
> Chris
> 
> On 22/10/2019 5:41 pm, Hans Goedbloed wrote:
>> I have been using g95 for my fortran codes for many years, but it did 
>> not work anymore after upgrading to macOS 10.14 Mojave. I was advised 
>> to install gccc9 from MacPorts instead. This I did through "sudo port 
>> selfupdate" and "sudo port install gcc9".
>>
>> This appeared to give all the required tools. When I then tried to 
>> compile and execute the simplest fortran  program test.f (the usual 
>> just writing of the message "Hello") by first compiling
>>
>> /opt/local/bin/gfortran-mp-9 -v -c test.f
>>
>> giving the required object file test.o, and then loading:
>>
>> /opt/local/bin/ld -v test.o
>>
>> this resulted in the messages
>>
>> @(#)PROGRAM:ld PROJECT:ld64-512.4
>>
>> BUILD 05:06:53 Aug 16 2019
>>
>> configured to support archs: armv6 armv7 armv7s arm64 arm64e arm64_32 
>> i386 x86_64 x86_64h armv6m armv7k armv7m armv7em
>>
>> Library search paths:
>>
>>            /usr/lib
>>
>> Framework search paths:
>>
>>            /Library/Frameworks/
>>
>>            /System/Library/Frameworks/
>>
>> Undefined symbols for architecture x86_64:
>>
>>   "__gfortran_set_args", referenced from:
>>
>>        _main in test.o
>>
>>   "__gfortran_set_options", referenced from:
>>
>>        _main in test.o
>>
>>   "__gfortran_st_write", referenced from:
>>
>>        _MAIN__ in test.o
>>
>>   "__gfortran_st_write_done", referenced from:
>>
>>        _MAIN__ in test.o
>>
>> ld: symbol(s) not found for architecture x86_64
>>
>> I thought installation of gcc9 would include everything. How should I 
>> fix this?​
>>
>>
>> Hans
>>
>>


More information about the macports-users mailing list