Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
580 views
in Technique[技术] by (71.8m points)

xcode - GFortran error: ld: library not found for -lSystem when trying to compile

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!

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...