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

丶灬走出姿态 提交于 2020-12-18 07:54:44

问题


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!


回答1:


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.




回答2:


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!




回答3:


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.



来源:https://stackoverflow.com/questions/56156520/gfortran-error-ld-library-not-found-for-lsystem-when-trying-to-compile

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!