lgfortran not found

大城市里の小女人 提交于 2019-12-28 15:21:10

问题


I am using Ubuntu 10.04 and trying to compile some code that uses gfortran. At some point Makefiles does:

-L. -lgfortran 

and I get the error

/usr/bin/ld: cannot find -lgfortran

although it is installed:

ldconfig -p  |  grep   fortran
    libgfortran.so.3 (libc6,x86-64) => /usr/lib/libgfortran.so.3

How can I fix it?

P.S: The Makefile:

## FLAGS

CC:= gcc
C++:= g++
CFLAGS:= -c -O -Dintel -g 
FC:= gfortran
FFLAGS:= -c -O -cpp -g
LD:= g++
LDFLAGS:= -O


WETTER_CGAL_FLAGS:=  -g


#WETTER-Data
WETTER_cgal: weather.cpp surface_alg.h $(WETTER_CGAL_OBJECTS) WATT_interface.h data.cpp
    $(C++) $(WETTER_CGAL_FLAGS) -c weather.cpp -frounding-math
    $(C++) -c data.cpp -frounding-math 
    $(LD) $(WETTER_CGAL_OBJECTS) weather.o data.o -o WETTER_cgal -L. -lgfortran -lgmp -lCGAL -frounding-math -fp-model

回答1:


Does by any chance your gfortran version differ from the version of your g++? Or maybe it is installed in a different location?

The -lname option (in this case name is gfortran) instructs the linker to search for a library file called libname.a in the library search path. If found and no static linking is enforced by the -[B]static option the linker will search once again for libname.so and link against it instead (if found). If libname.a is not found an error will be given despite the presence of libname.so.

There should be a libgfortran.a somewhere in your gfortran installation. Search for it with find and provide the path to g++ with -L/path/to/compiler/libs. If g++ is the same version as your gfortran the path to libgfortran.a will already be present in the library search path (since both C/C++ and Fortran static libraries reside in the same place). It will not be present if both compilers differ in their version though.

For example on a 64-bit RedHat based system libgfortran.a is located in /usr/lib/gcc/x86_64-redhat-linux/<GCC version>/ while the shared libgfortran.so.* are located in /usr/lib64.

An alternative solution is to replace -lgfortran with /usr/lib/libgfortran.so.3.

The -L. option is rather related to -lCGAL than to -lgfortran.




回答2:


I had the same issue today when compiling ATLAS and was able to fix it using a symbolic link from libgfortran.so.3 to libgfortran.so.




回答3:


Just make sure you:

gcc --version

And

gfortan --version

Is the same.

/usr/bin/ 

Contains the different versions.

Eg: If gcc--version returns 4.7.3 and gfortran --version 4.8, a simple hack could be to do the following.

sudo cp /usr/bin/gcc-4.8 /usr/bin/gcc

It should work.




回答4:


I had the same problem and tried the following command. The problem was solved using this:

sudo ln -s /usr/lib/x86_64-linux-gnu/libgfortran.so.3 /usr/lib/libgfortran.so



来源:https://stackoverflow.com/questions/10881002/lgfortran-not-found

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