gcc - 如何编译lapack,以便在安装octave的过程中可以正确使用?

标签 gcc installation fortran octave lapack

我正在尝试在运行 redhat+IBM LSF 的集群中从源代码安装最新的 octave 3.8.1。除了我自己的主目录之外,我没有其他任何地方的写访问权限,这就是为什么我必须从源代码安装 octave。集群提供的 blas 和 lapack 不起作用,所以我必须自己构建它们。我现在已经完成了 blas 和 lapack 的编译并通过了 ./configure ,但是我运行make的时候,报错如下:

enter image description here

这些是我用来构建自己的步骤 BLASLAPACK . BLAS的来源在~/src/BLAS而 LAPACK 的来源在 ~/src/lapack-3.5.0并且 octave 3.8.1 的来源在 ~/src/octave-3.8.1 .
只有两个模块,1) pcre/8.33 2) acml/5.3.1/gfortran64 ,加载,我使用编译 BLAS 共享库

gfortran -shared -O2 *.f -o libblas.so -fPIC

和静态库使用
gfortran -O2 -c *.f -fPIC
ar cr libblas.a *.o

然后我复制共享库libblas.so到 ~/src/octave-3.8.1。 make.inc的内容lapack 目录中的文件是:
####################################################################
#  LAPACK make include file.                                       #
#  LAPACK, Version 3.5.0                                           #
#  November 2013                                                   #
####################################################################
#
SHELL = /bin/sh
#  
#  Modify the FORTRAN and OPTS definitions to refer to the
#  compiler and desired compiler options for your machine.  NOOPT
#  refers to the compiler options desired when NO OPTIMIZATION is
#  selected.  Define LOADER and LOADOPTS to refer to the loader and 
#  desired load options for your machine.
#
FORTRAN  = gfortran 
OPTS     = -shared -O2 -fPIC
DRVOPTS  = $(OPTS)
NOOPT    = -O0 -frecursive
LOADER   = gfortran
LOADOPTS =
#
# Timer for the SECOND and DSECND routines
#
# Default : SECOND and DSECND will use a call to the EXTERNAL FUNCTION ETIME
#TIMER    = EXT_ETIME
# For RS6K : SECOND and DSECND will use a call to the EXTERNAL FUNCTION ETIME_
# TIMER    = EXT_ETIME_
# For gfortran compiler: SECOND and DSECND will use a call to the INTERNAL FUNCTION ETIME
TIMER    = INT_ETIME
# If your Fortran compiler does not provide etime (like Nag Fortran Compiler, etc...)
# SECOND and DSECND will use a call to the INTERNAL FUNCTION CPU_TIME
# TIMER    = INT_CPU_TIME
# If neither of this works...you can use the NONE value... In that case, SECOND and DSECND will always return 0
# TIMER     = NONE
#
#  Configuration LAPACKE: Native C interface to LAPACK
#  To generate LAPACKE library: type 'make lapackelib'
#  Configuration file: turned off (default)
#  Complex types: C99 (default)
#  Name pattern: mixed case (default)
#  (64-bit) Data model: LP64 (default)
#
# CC is the C compiler, normally invoked with options CFLAGS.
#
CC = gcc
CFLAGS = -O3
#
#  The archiver and the flag(s) to use when building archive (library)
#  If you system has no ranlib, set RANLIB = echo.
#
ARCH     = ar
ARCHFLAGS= cr
RANLIB   = ranlib
#
#  Location of the extended-precision BLAS (XBLAS) Fortran library
#  used for building and testing extended-precision routines.  The
#  relevant routines will be compiled and XBLAS will be linked only if
#  USEXBLAS is defined.
#
# USEXBLAS    = Yes
XBLASLIB     =
# XBLASLIB    = -lxblas
#
#  The location of the libraries to which you will link.  (The 
#  machine-specific, optimized BLAS library should be used whenever
#  possible.)
#
#BLASLIB      = ../../librefblas.a
BLASLIB      = ~/src/BLAS/libblas.a
LAPACKLIB    = liblapack.a
TMGLIB       = libtmglib.a
LAPACKELIB   = liblapacke.a

然后我输入 make 来编译 LAPACK。编译后,我复制了输出liblapack.a到 ~/src/octave-3.8.1。
./configure命令行是:
./configure --prefix=$HOME/bin/octave --with-blas=./libblas.so --with-lapack=$HOME/src/octave-3.8.1/liblapack.a --disable-readline --enable-64

我可以通过./configure。然后我输入 make尝试构建 octave 3.8.1,我得到了上述错误。

来自 make.inc文件可以看出我遵循了编译器“recompile with -fPIC”的建议,并相应地修改了make.inc。我还添加了-shared切换到 OPTS多变的。此外,我尝试过使用旧的 LAPACK 版本但无法正常工作。我真的不知道为什么错误仍然出现。所以我想知道你能否告诉我如何编译LAPACK库,以便在安装 octave 3.8.1 期间可以正确使用它。以下两点可能值得考虑。 (1) 我应该将 lapack 编译为静态库还是共享库? (2) 应-fPIC开关应用于 lapack 编译或 octave 的 make ?如果是后者,如何应用-fPIC来制作?您不必局限于上述两点,因为错误可能还有其他原因。欢迎任何解决此问题的建议。如果您需要任何其他信息,请告诉我。谢谢你。

最佳答案

刚刚在我老板的野兽上编译了lapack共享库...这里是a link这几乎做对了。
我做了一些改变:

(1) 将 -fPIC 添加到

OPTS & NOOPT in make.inc

(2) 将make.inc中的名称改为.so
BLASLIB = ../../libblas.so

LAPACKLIB = ../liblapack.so

(3) 在 ./SRC 中,将 Makefile 从
../$(LAPACKLIB): $(ALLOBJ)
    $(ARCH) $(ARCHFLAGS) $@ $(ALLOBJ)
    $(RANLIB) $@


../$(LAPACKLIB): $(ALLOBJ)
    $(LOADER) $(LOADOPTS) -shared -Wl,-soname,liblapack.so -o $@ $(ALLOBJ) ../libblas.so

因为 lapack 正在调用 blas,如果你错过了最后一部分,你的 liblapack.so 将会失败!您需要针对 libblas.so 链接 liblapack.so ( libatlas.so 也可以)。您可以使用“ldd liblapack.so”来检查它的依赖关系。如果您在那里看到 libblas.so,那么您几乎做对了。

(4) 在 ./BLAS/SRC 中,将 Makefile 从
$(BLASLIB): $(ALLOBJ)
$(ARCH) $(ARCHFLAGS) $@ $(ALLOBJ)
$(RANLIB) $@


$(BLASLIB): $(ALLOBJ)
$(LOADER) $(LOADOPTS) -z muldefs -shared -Wl,-soname,libblas.so -o $@ $(ALLOBJ)

(5)我不需要 libtmg.so 所以我没有改变它......

make blaslib 

然后
make lapacklib

您将编译它们。我检查 liblapack.so 并在其上构建一个 numpy 并加载 Python ctypes.cdll。我所有的工作都是为了解决特征值和特征向量......所以应该没问题......

(6) 您可能需要将 LD_LIBRARY_PATH 设置到您保存库文件的位置。
谷歌它...如果不是由管理员设置,那么
export LD_LIBRARY_PATH=path-to-lib

如果已经设置,那么
export LD_LIBRARY_PATH=path-to-lib:$LD_LIBRARY_PATH

覆盖您的默认库。

这样您就不会出现 ld 链接错误。祝你好运!!

在 lapack-3.7.0 中,SRC/Makefile 中有多余的行。只需删除它们即可解决您的错误。

关于gcc - 如何编译lapack,以便在安装octave的过程中可以正确使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23463240/

相关文章:

ruby-on-rails - Ruby on Rails - 无法将 "\x89"从 ASCII-8BIT 转换为 xxx/xxxx/xxxx 的 UTF-8

fortran - 具有无限多态实体的 Fortran 是否可以进行通用解析

arrays - 如何在Fortran中初始化一个大数组?

c++ - 如何使用 GCC 配置 Mono Include Directory 路径

c - PowerPC 内联程序集 : Load C Value into Register

gcc - 在 Dev-C++ 中的 GCC 内联汇编中定义字节(Windows 上 AT&T 语法中的 .ascii)

c - 为什么 '\b' 在下面的 C 代码中不起作用?

windows - Oracle Lite 10g 安装程序未在我的机器上检测到 JDK

configuration - Kohana 配置文件在哪里?

fortran - 我可以用数字调用 fortran 日志函数吗?