使用HDF5的Fortran代码的makefile中的未定义参考错误



我正在尝试编译使用HDF5的Fortran 90代码。为此,我正在使用以下makefile:

# Location of HDF5 binaries (with include/ and lib/ underneath)
HDF5 = /fs/posgrado16/other0/guido/libraries/hdf5/serial
# Compiler
FC        = gfortran
# ------ No machine-specific paths/variables after this  -----
FORTRANLIB=-I$(HDF5)/include $(HDF5)/lib/libhdf5_fortran.a
FSOURCE = h5_crtgrpar.f90
OBJECTS = $(FSOURCE:.f90=.o)
EXECUTABLE = $(FSOURCE:.f90=.exe)
LIBSHDF = $(FORTRANLIB) $(HDF5)/lib/libhdf5.a

all:$(EXECUTABLE)

$(EXECUTABLE):$(OBJECTS)
    $(FC) -o $@ $^ $(LIBSHDF)
$(OBJECTS):$(FSOURCE)
    $(FC) -c $@ $< $(LIBSHDF)

.PHONY : clean
 clean:
    rm -f $(FSOURCE) $(OBJECTS) *.h5

但是,我会收到以下错误:

$ make -f Makefilef 
gfortran -o h5_crtgrpar.exe h5_crtgrpar.o -I/fs/posgrado16/other0/guido       /libraries/hdf5/serial/include /fs/posgrado16/other0/guido/libraries/hdf5/serial/lib/libhdf5_fortran.a /fs/posgrado16/other0/guido/libraries /hdf5/serial/lib/libhdf5.a 
/fs/posgrado16/other0/guido/libraries/hdf5/serial/lib/libhdf5.a(H5PL.o): In    function `H5PL_term_interface':
H5PL.c:(.text+0x205): undefined reference to `dlclose'
/fs/posgrado16/other0/guido/libraries/hdf5/serial/lib/libhdf5.a(H5PL.o): In   function `H5PL_load':
H5PL.c:(.text+0x477): undefined reference to `dlsym'
H5PL.c:(.text+0x5be): undefined reference to `dlopen'
H5PL.c:(.text+0x5d7): undefined reference to `dlsym'
H5PL.c:(.text+0x704): undefined reference to `dlclose'
H5PL.c:(.text+0x789): undefined reference to `dlerror'
H5PL.c:(.text+0x960): undefined reference to `dlclose'
collect2: error: ld returned 1 exit status
make: *** [h5_crtgrpar.exe] Error 1

我不知道错误是什么。可能,我的makefile有问题。

启用了HDF5,您可以替换

FC        = gfortran

FC        = h5fc

并跳过所有HDF5标志,因为h5fc包装器会照顾那些。

如果您以其名称调用编译器的特定原因,可以通过调用

来了解需要哪些标志
h5fc -show

将向您显示编译器中添加了哪些标志。

在我的计算机上(带Gfortran的Linux(,结果是:

gfortran -g -O2 -fstack-protector-strong -I/usr/include/hdf5/serial -L/usr/lib/x86_64-linux-gnu/hdf5/serial /usr/lib/x86_64-linux-gnu/hdf5/serial/libhdf5hl_fortran.a /usr/lib/x86_64-linux-gnu/hdf5/serial/libhdf5_hl.a /usr/lib/x86_64-linux-gnu/hdf5/serial/libhdf5_fortran.a /usr/lib/x86_64-linux-gnu/hdf5/serial/libhdf5.a -Wl,-z,relro -lpthread -lz -ldl -lm -Wl,-rpath -Wl,/usr/lib/x86_64-linux-gnu/hdf5/serial

通常,您可以使用较少的标志来获得,而您可以通过一些实验找到。

给出了您报告的错误消息,您缺少启用动态链接库的链接的-ldl标志,请参阅此其他问题。

最新更新