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'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
更新:我尝试了建议并使用自制软件从 gcc 包安装了 gfortran 版本,这给了我一个更新版本的 gfortran,我的问题得到了解决!
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.
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.
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.
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
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 added this to my ~/.profile
:
export SDKROOT=$(xcrun --sdk macosx --show-sdk-path)
export LIBRARY_PATH="$SDKROOT/usr/lib"
And it works.
谢谢,这也对我有用,非常感谢(来自 hpc.sourceforge.net 的 Catalina、gcc 和 gfortran 9.2)ADR
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.