我正在尝试编译大型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
答案 0 :(得分:1)
我认为这是因为您的大型数组位于COMMON
块中。这会将数组放在TEXT
段中。将此与--enable-static-exec
结合使用意味着TEXT
段超过2GB。
删除--enable-static-exec
您现在正在使用动态库,并设法将TEXT
段拉低至2GB以下。
我敢说,如果您需要-mcmodel=large
,则不应将其与--enable-static-exec
混合使用。