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

问题描述

我正在使用 Ubuntu 10.04 并尝试编译一些使用 gfortran 的代码.在某些时候 Makefiles 会:

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

-L. -lgfortran

我得到了错误

/usr/bin/ld: cannot find -lgfortran

虽然已安装:

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

我该如何解决?

P.S:Makefile:

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

推荐答案

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

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

-lname 选项(在这种情况下,namegfortran)指示链接器搜索名为 libname 的库文件.a 在库搜索路径中.如果找到并且 -[B]static 选项未强制执行静态链接,则链接器将再次搜索 libname.so 并对其进行链接(如果找到).如果未找到 libname.a,尽管存在 libname.so,但仍会报错.

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.

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

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.

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

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.

另一种解决方案是将 -lgfortran 替换为 /usr/lib/libgfortran.so.3.

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

-L. 选项与 -lCGAL 的相关性高于 -lgfortran.

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

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

05-24 09:15