HDF5库不能使用-mcmodel = large进行编译

时间:2014-08-27 14:20:55

标签: gcc fortran gfortran hdf5

我正在尝试编译大型FORTRAN应用程序,需要将HDF5库链接到它。该程序需要使用gfortran进行编译,并且需要 -mcmodel = large 选项。仅使用 -mcmodel = medium 时,我收到如下错误消息:

:(.text+0x3019): relocation truncated to fit: R_X86_64_32 against `.lrodata'

我正在使用configure编译HDF5库:

./configure --enable-static-exec --enable-fortran FCFLAGS="-mcmodel=large" CFLAGS="-mcmodel=large"
make -j
make install

在编译FORTRAN程序时,我得到了:

H5_ff.f90:(.text+0x23): relocation truncated to fit: R_X86_64_PC32 against symbol `predefined_types_' defined in COMMON section in /tmp/ccHO0WzS.o
H5_ff.f90:(.text+0x3c): relocation truncated to fit: R_X86_64_PC32 against symbol `predefined_types_' defined in COMMON section in /tmp/ccHO0WzS.o
H5_ff.f90:(.text+0x52): relocation truncated to fit: R_X86_64_PC32 against symbol `predefined_types_' defined in COMMON section in /tmp/ccHO0WzS.o
H5_ff.f90:(.text+0x68): relocation truncated to fit: R_X86_64_PC32 against symbol `predefined_types_' defined in COMMON section in /tmp/ccHO0WzS.o
H5_ff.f90:(.text+0x89): relocation truncated to fit: R_X86_64_PC32 against symbol `predefined_types_' defined in COMMON section in /tmp/ccHO0WzS.o
H5_ff.f90:(.text+0x9f): relocation truncated to fit: R_X86_64_PC32 against symbol `predefined_types_' defined in COMMON section in /tmp/ccHO0WzS.o
H5_ff.f90:(.text+0xb5): relocation truncated to fit: R_X86_64_PC32 against symbol `predefined_types_' defined in COMMON section in /tmp/ccHO0WzS.o

我在linux上使用gfortran版本:4.7.2。

使用 -mcmodel = medium 进行编译有效,但前提是我减少了FORTRAN程序中变量的大小。那么,在使用-mcmodel = large时,如何用gfortran和HDF5库编译FORTRAN程序呢?

我无法在这里展示真实的节目,但为了得到这个想法,这里有一个重现错误的fortran程序:

PROGRAM test
IMPLICIT NONE
DOUBLE PRECISION tst(1000,1000,1000,1),bf
COMMON /tt/ tst
bf = tst(1,1,1,1)
print *,'Hello World.'
call kk
END PROGRAM


SUBROUTINE kk
USE H5LT
USE HDF5
IMPLICIT NONE
INTEGER(KIND=4)::errcode
call h5open_f(errcode)
print *,"Hello Subroutine."
END SUBROUTINE

用以下内容编译:

gfortran -o tst -mcmodel=large tst.f90 -I./hdf5/hdf5/include -L./hdf5/hdf5/lib ./hdf5/hdf5/lib/libhdf5hl_fortran.a ./hdf5/hdf5/lib/libhdf5_hl.a ./hdf5/hdf5/lib/libhdf5_fortran.a ./hdf5/hdf5/lib/libhdf5.a -lz -lrt -ldl -lm -Wl,-rpath -Wl,./hdf5/hdf5/lib

并假设./hdf5/hdf5中的HDF5库。但是,这个程序将使用 -mcmodel = medium 进行编译和运行,但我的真实程序却没有。我无法想出一个简单的程序,该程序无法使用 -mcmodel = medium 编译,但 -mcmodel = large 。我甚至不确定为什么 -mcmodel = medium 不能用于真正的程序。

HDF5库可在此处找到:http://www.hdfgroup.org/HDF5/release/obtain5.html

1 个答案:

答案 0 :(得分:1)

我认为这是因为您的大型数组位于COMMON块中。这会将数组放在TEXT段中。将此与--enable-static-exec结合使用意味着TEXT段超过2GB。

删除--enable-static-exec您现在正在使用动态库,并设法将TEXT段拉低至2GB以下。

我敢说,如果您需要-mcmodel=large,则不应将其与--enable-static-exec混合使用。