gfortran does not work properly when Conda is installed on MacOs Ventura - gcc

I've been trying to get gfortran working on MacOs Ventura(with a M1 chip) for quite some time.
Briefly, the big problem is that gfortran works (when installed via homebrew) until the moment I install Anaconda/conda. After installing Conda, gfortran stops working and I don't know how to make it work correctly. And I need both (conda and gfortran) installed and working.
If I install gcc via homebrew, gfortran works perfectly(version 12.2.0). However, when installing Conda the following message appears when I try to compile something in fortran(in this case it was just a "Hello World"):
gfortran hello.f90 -o trash
ld: unsupported tapi file type '!tapi-tbd' in YAML file '/Library/Developer/CommandLineTools/SDKs/MacOSX13.sdk/usr/lib/libSystem.tbd' for architecture arm64
collect2: error: ld returned 1 exit status
To get around this, I uninstalled gcc from homebrew and installed it using Conda. I installed the latest available version(11.2.0) using conda install gfortran=11.2.0.
gfortran —version
gfortran: warning: could not understand version 13.02.00
GNU Fortran (GCC) 11.2.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
And when I run "which gfortran”, it returns:
/Users/Odilon/opt/anaconda3/bin/gfortran
However, when trying to compile something the following message is displayed(I am using gfortran hello.f90 -o trash, where "trash" is just the name of the executable I chose):
gfortran: warning: could not understand version 13.02.00
ld: -rpath can only be used when targeting Mac OS X 10.5 or later
collect2: error: ld returned 1 exit status
xcode is in the last version(14.2) and Command Line tools is installed.
I need gfortran and conda to be installed and working normally on the MacOS.
How do I resolve these errors?
How can I make gfortran work normally even with Conda installed on the system?
Thanks in advance for the answers and help!

Related

gfortran cannot match MacOS Ventura version

The new MacOS Ventura seems to have broken gfortran MacOS version control. To reproduce my error you only have to do
gfortran --version
And the output is
gfortran: warning: could not understand version ‘13.00.00’
GNU Fortran (GCC) 11.3.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
This in itself is just a warning so it might not be a big deal but it breaks "./configure" scripts that require some MacOS versions, e.g. if you try to compile LoopTools you get the following error (in the log file)
arm64-apple-darwin20.0.0-gfortran: warning: could not understand version '13.00.00'
ld: -rpath can only be used when targeting Mac OS X 10.5 or later
collect2: error: ld returned 1 exit status
Since the version cannot be properly read it cannot be compared.
Is there some sort of work around this bug?
I had installed gfortran through conda but aparantly the version is from last year.
I solved it by removing it from conda (had to remove conda entirely due to linking issues) and installed it with brew : brew install gcc.

Why my Make file doesn't compiling in Mac and display ld: library not found for -lSystem? [duplicate]

I am getting a strange error when trying to compile a simple fortran-90 file using gfortran. I am working on a macOS mojave system. I have gfortran 8.2.0 installed and I checked to be sure of this by doing the following:
Input: gfortran --version
Output: GNU Fortran (GCC) 8.2.0
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
Which indicates that gfortran installed correctly and I also confirmed this by typing simply: gfortran, into the terminal, which returns:
gfortran: fatal error: no input files
compilation terminated.
However, when I try to compile my file like so:
gfortran hello.f90 -o hello.x
I get an error which reads:
ld: library not found for -lSystem
collect2: error: ld returned 1 exit status
I've tried compiling in different ways and I also tried setting the LD_LIBRARY_PATH in .bash_profile as described by https://gcc.gnu.org/wiki/GFortranBinaries32Linux but I still get the same error. The gfortran directory has the pathname: /usr/local/gfortran, however another gfortran which is not a directory can be found in /usr/local/bin
Typing:
which gfortran
Outputs:
/usr/local/bin/gfortran
And a long list search of this directory:
Input: ls -l /usr/local/bin/gfortran
Output: lrwxr-xr-x 1 root wheel 32 15 May 14:07
/usr/local/bin/gfortran -> /usr/local/gfortran/bin/gfortran
How can I fix this where everything seems to be correctly installed?
Any help would be greatly appreciated!
On macOS Big Sur v11.1:
Relevant SO post: https://apple.stackexchange.com/questions/408999/gfortran-compiler-error-on-mac-os-big-sur
The fix is to add the stdlib to your $LIBRARY_PATH. For some reason or another it isn't in your standard $PATH anymore on 11.1.
export LIBRARY_PATH="$LIBRARY_PATH:/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib"
(or add it to login file and restart terminal).
I added this to my ~/.profile:
export SDKROOT=$(xcrun --sdk macosx --show-sdk-path)
export LIBRARY_PATH="$LIBRARY_PATH:$SDKROOT/usr/lib"
And it works.
I'll also chime in (19 Dec 2020) that I just updated from MacOS Mojave to Catalina and suddenly got this error.
It resolved itself with
brew reinstall gcc
brew reinstall gfortran
Update: I tried what was suggested and installed the gfortran build from the gcc package using homebrew which gave me a newer version of gfortran and my problem was fixed!
I had the same problem, but installing gfortran build from the gcc package using homebrew did not help. Instead, I installed the whole gcc using homebrew:
brew install gcc
and that solved the problem.
For those using MacPorts.
# Installed `gcc8` and `gcc_select`
sudo port install gcc_select gcc8
# then to create "gfortran" softlink to "gfortran-mp-8"
sudo port select --set gcc gcc8
# and added to my .profile
export LIBRARY_PATH="$LIBRARY_PATH:/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib"
I did ls -l /Library/Developer/CommandLineTools/SDKs/ and found that Xcode had installed one SDK for Catalina and one for Big Sur. I changed the soft link for MacOSX.sdk to point to the Catalina version.
Just placed this line at the end of .zshrc:
export LIBRARY_PATH="$LIBRARY_PATH:/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib"
and ran my Fortran code again to compile – success! The issue with -lSystem has been solved in my macOS system.
I had this problem, and I'd tried lots of thing to solve the problem, but only using these "both" commands solved it:
brew reinstall gcc
brew reinstall gfortran
I recently had this
ld: library not found for -lSystem
problem after upgrading Mac OS from v10 to v11 (Big Sur). I am using Xcode 12.3 and I used brew install gcc to install gfortran 10.2.0. I still saw the error after trying brew reinstall gcc. I was able to solve the problem using:
brew install gfortran
but I do not know why this works.

Could not build gem5 on a machine with anaconda: "lto1: fatal error: bytecode stream"

When I tried to build gem5 with command scons build/X86/gem5.opt -j12, I received an error message saying
lto1: fatal error: bytecode stream in file '/home/beihai/anaconda3/lib/python3.8/config-3.8-x86_64-linux-gnu/libpython3.8.a' generated with LTO version 6.0 instead of the expected 8.1
I think it might be the problem of wrong gcc version. But I do not know how to fix it.
My system is Kubuntu 20.04
By running gcc -v, I got the global gcc version gcc version 9.3.0
By running /home/beihai/anaconda/envs/gem5build/bin/x86_64-conda_cos6-linux-gnu-gcc -v, I got the anaconda gcc version gcc version 7.3.0 (crosstoll-NG 1.23.0.449-a04d0)
Please tell me how to fix this problem.
I came across almost the same issue, except that mine said "LTO version 6.0 instead of the expected 6.2".
I searched for general solution for LTO compatibility issue and got some inspiration from this link: https://github.com/rust-lang/rust/issues/57176
Quick take from the above link: "I've looked into how this is related to python and found that the error only happens with python installed through anaconda."
So I removed my entire anaconda software package, and removed the build directory inside Gem5, and rerun the scon commands with an additional "--force-lto" arguments, now the installation is successful. Hope it can solve your issue as well.
The command I used: "scons --force-lto build/X86/gem5.opt -j6"
My setups is:
Ubuntu 18 withe kernel 4.15.0-134-generic
g++ --version = g++ (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0

library not found for -lSystem - M1 MacBook - Radmc3d [duplicate]

I am getting a strange error when trying to compile a simple fortran-90 file using gfortran. I am working on a macOS mojave system. I have gfortran 8.2.0 installed and I checked to be sure of this by doing the following:
Input: gfortran --version
Output: GNU Fortran (GCC) 8.2.0
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
Which indicates that gfortran installed correctly and I also confirmed this by typing simply: gfortran, into the terminal, which returns:
gfortran: fatal error: no input files
compilation terminated.
However, when I try to compile my file like so:
gfortran hello.f90 -o hello.x
I get an error which reads:
ld: library not found for -lSystem
collect2: error: ld returned 1 exit status
I've tried compiling in different ways and I also tried setting the LD_LIBRARY_PATH in .bash_profile as described by https://gcc.gnu.org/wiki/GFortranBinaries32Linux but I still get the same error. The gfortran directory has the pathname: /usr/local/gfortran, however another gfortran which is not a directory can be found in /usr/local/bin
Typing:
which gfortran
Outputs:
/usr/local/bin/gfortran
And a long list search of this directory:
Input: ls -l /usr/local/bin/gfortran
Output: lrwxr-xr-x 1 root wheel 32 15 May 14:07
/usr/local/bin/gfortran -> /usr/local/gfortran/bin/gfortran
How can I fix this where everything seems to be correctly installed?
Any help would be greatly appreciated!
On macOS Big Sur v11.1:
Relevant SO post: https://apple.stackexchange.com/questions/408999/gfortran-compiler-error-on-mac-os-big-sur
The fix is to add the stdlib to your $LIBRARY_PATH. For some reason or another it isn't in your standard $PATH anymore on 11.1.
export LIBRARY_PATH="$LIBRARY_PATH:/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib"
(or add it to login file and restart terminal).
I added this to my ~/.profile:
export SDKROOT=$(xcrun --sdk macosx --show-sdk-path)
export LIBRARY_PATH="$LIBRARY_PATH:$SDKROOT/usr/lib"
And it works.
I'll also chime in (19 Dec 2020) that I just updated from MacOS Mojave to Catalina and suddenly got this error.
It resolved itself with
brew reinstall gcc
brew reinstall gfortran
Update: I tried what was suggested and installed the gfortran build from the gcc package using homebrew which gave me a newer version of gfortran and my problem was fixed!
I had the same problem, but installing gfortran build from the gcc package using homebrew did not help. Instead, I installed the whole gcc using homebrew:
brew install gcc
and that solved the problem.
For those using MacPorts.
# Installed `gcc8` and `gcc_select`
sudo port install gcc_select gcc8
# then to create "gfortran" softlink to "gfortran-mp-8"
sudo port select --set gcc gcc8
# and added to my .profile
export LIBRARY_PATH="$LIBRARY_PATH:/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib"
I did ls -l /Library/Developer/CommandLineTools/SDKs/ and found that Xcode had installed one SDK for Catalina and one for Big Sur. I changed the soft link for MacOSX.sdk to point to the Catalina version.
Just placed this line at the end of .zshrc:
export LIBRARY_PATH="$LIBRARY_PATH:/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib"
and ran my Fortran code again to compile – success! The issue with -lSystem has been solved in my macOS system.
I had this problem, and I'd tried lots of thing to solve the problem, but only using these "both" commands solved it:
brew reinstall gcc
brew reinstall gfortran
I recently had this
ld: library not found for -lSystem
problem after upgrading Mac OS from v10 to v11 (Big Sur). I am using Xcode 12.3 and I used brew install gcc to install gfortran 10.2.0. I still saw the error after trying brew reinstall gcc. I was able to solve the problem using:
brew install gfortran
but I do not know why this works.

compiling F90 code on mac osx catalina: library issues [duplicate]

I am getting a strange error when trying to compile a simple fortran-90 file using gfortran. I am working on a macOS mojave system. I have gfortran 8.2.0 installed and I checked to be sure of this by doing the following:
Input: gfortran --version
Output: GNU Fortran (GCC) 8.2.0
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
Which indicates that gfortran installed correctly and I also confirmed this by typing simply: gfortran, into the terminal, which returns:
gfortran: fatal error: no input files
compilation terminated.
However, when I try to compile my file like so:
gfortran hello.f90 -o hello.x
I get an error which reads:
ld: library not found for -lSystem
collect2: error: ld returned 1 exit status
I've tried compiling in different ways and I also tried setting the LD_LIBRARY_PATH in .bash_profile as described by https://gcc.gnu.org/wiki/GFortranBinaries32Linux but I still get the same error. The gfortran directory has the pathname: /usr/local/gfortran, however another gfortran which is not a directory can be found in /usr/local/bin
Typing:
which gfortran
Outputs:
/usr/local/bin/gfortran
And a long list search of this directory:
Input: ls -l /usr/local/bin/gfortran
Output: lrwxr-xr-x 1 root wheel 32 15 May 14:07
/usr/local/bin/gfortran -> /usr/local/gfortran/bin/gfortran
How can I fix this where everything seems to be correctly installed?
Any help would be greatly appreciated!
On macOS Big Sur v11.1:
Relevant SO post: https://apple.stackexchange.com/questions/408999/gfortran-compiler-error-on-mac-os-big-sur
The fix is to add the stdlib to your $LIBRARY_PATH. For some reason or another it isn't in your standard $PATH anymore on 11.1.
export LIBRARY_PATH="$LIBRARY_PATH:/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib"
(or add it to login file and restart terminal).
I added this to my ~/.profile:
export SDKROOT=$(xcrun --sdk macosx --show-sdk-path)
export LIBRARY_PATH="$LIBRARY_PATH:$SDKROOT/usr/lib"
And it works.
I'll also chime in (19 Dec 2020) that I just updated from MacOS Mojave to Catalina and suddenly got this error.
It resolved itself with
brew reinstall gcc
brew reinstall gfortran
Update: I tried what was suggested and installed the gfortran build from the gcc package using homebrew which gave me a newer version of gfortran and my problem was fixed!
I had the same problem, but installing gfortran build from the gcc package using homebrew did not help. Instead, I installed the whole gcc using homebrew:
brew install gcc
and that solved the problem.
For those using MacPorts.
# Installed `gcc8` and `gcc_select`
sudo port install gcc_select gcc8
# then to create "gfortran" softlink to "gfortran-mp-8"
sudo port select --set gcc gcc8
# and added to my .profile
export LIBRARY_PATH="$LIBRARY_PATH:/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib"
I did ls -l /Library/Developer/CommandLineTools/SDKs/ and found that Xcode had installed one SDK for Catalina and one for Big Sur. I changed the soft link for MacOSX.sdk to point to the Catalina version.
Just placed this line at the end of .zshrc:
export LIBRARY_PATH="$LIBRARY_PATH:/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib"
and ran my Fortran code again to compile – success! The issue with -lSystem has been solved in my macOS system.
I had this problem, and I'd tried lots of thing to solve the problem, but only using these "both" commands solved it:
brew reinstall gcc
brew reinstall gfortran
I recently had this
ld: library not found for -lSystem
problem after upgrading Mac OS from v10 to v11 (Big Sur). I am using Xcode 12.3 and I used brew install gcc to install gfortran 10.2.0. I still saw the error after trying brew reinstall gcc. I was able to solve the problem using:
brew install gfortran
but I do not know why this works.

Resources