本文介绍了找不到lgfortran的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Ubuntu 10.04并尝试编译一些使用gfortran的代码。在某些时候,Makefiles会这样做:

  -L。 -lgfortran 

我得到错误

  / usr / bin / ld:找不到-lgfortran 

虽然它已安装:

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

我该如何解决它?

$ b:b

PS:Makefile:

  ##标记

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


WETTER_CGAL_FLAGS:= -g


#WETTER-数据
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


解决方案

您的 gfortran 版本有没有与您的 g ++ 版本有所不同?或者它可能安装在不同的位置?

-lname 选项(在这种情况下 name 是 gfortran )指示链接器搜索名为 libname.a 选项强制执行,链接器将再次搜索 libname.so 并反向链接(如果找到)。如果未找到 libname.a ,即使存在 libname.so ,也会发出错误。



您的 gfortran 安装中应该有一个 libgfortran.a 。使用 find 搜索它,并使用 -L / path / to提供< g ++ 的路径/编译器/库。如果 g ++ 与您的 gfortran 版本相同,则 libgfortran.a 已经存在于库搜索路径中(因为C / C ++和Fortran静态库都驻留在同一位置)。如果两个编译器的版本不同,它将不会出现。



例如,在基于64位RedHat的系统 libgfortran.a 位于 / usr / lib / gcc / x86_64-redhat-linux /< GCC版本> / ,而共享 libgfortran .so。* 位于 / usr / lib64 。



另一种解决方案用 /usr/lib/libgfortran.so.3 替换 -lgfortran 。



-L。选项与 -lCGAL 之间的关系要比 -lgfortran 。


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
解决方案

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.

这篇关于找不到lgfortran的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 06:05