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
1.2k views
in Technique[技术] by (71.8m points)

ubuntu - lgfortran not found

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
See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

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.


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

...