找不到现有的图书馆

时间:2015-05-22 12:52:41

标签: linux ld gfortran hdf5

我正在编译一个fortran代码,它需要安装在本地目录中的hdf5库。这是我的Makefile:

<dependency>
   <groupId>org.springframework.data</groupId>
   <artifactId>spring-data-elasticsearch</artifactId>
   <version>1.2.0.RELEASE</version>
</dependency>

在链接过程中我收到此错误:

FC = gfortran
FCFLAGS = -g -fcheck=all -Wall -fdefault-real-8
INCLUDES = -I/home/bharat/hdf5/include
LFLAGS = -L/home/bharat/hdf5/lib
LIBS= -lhdf5_fortran

main: main.o param.o dmotifs.o ssa.o
    $(FC) $(LFLAGS) $(LIBS) -o main $^

param.o: param.f90
    $(FC) $(FCFLAGS) -c $<

dmotifs.o: dmotifs.f90 param.o
    $(FC) $(FCFLAGS) -c $<

ssa.o: ssa.f90 dmotifs.o
    $(FC) $(FCFLAGS) -c $<

main.o: main.f90 param.o dmotifs.o ssa.o
    $(FC) $(FCFLAGS) -c $(INCLUDES) $<

clean:
    rm -f *.o *.mod *.MOD

这通常在未指定hdf-fortran库/home/bharat/stochastic/main.f90:142: undefined reference to `__h5lib_MOD_h5open_f' /home/bharat/stochastic/main.f90:143: undefined reference to `__h5f_MOD_h5fcreate_f' /home/bharat/stochastic/main.f90:144: undefined reference to `__h5s_MOD_h5screate_simple_f' /home/bharat/stochastic/main.f90:145: undefined reference to `__h5d_MOD_h5dcreate_f' /home/bharat/stochastic/main.f90:158: undefined reference to `__h5d_provisional_MOD_h5dwrite_integer_3' /home/bharat/stochastic/main.f90:147: undefined reference to `__h5d_MOD_h5dclose_f' /home/bharat/stochastic/main.f90:148: undefined reference to `__h5s_MOD_h5sclose_f' /home/bharat/stochastic/main.f90:149: undefined reference to `__h5s_MOD_h5screate_simple_f' /home/bharat/stochastic/main.f90:150: undefined reference to `__h5d_MOD_h5dcreate_f' /home/bharat/stochastic/main.f90:158: undefined reference to `__h5_dble_interface_MOD_h5dwrite_double_2' /home/bharat/stochastic/main.f90:154: undefined reference to `__h5d_MOD_h5dclose_f' /home/bharat/stochastic/main.f90:155: undefined reference to `__h5s_MOD_h5sclose_f' /home/bharat/stochastic/main.f90:156: undefined reference to `__h5f_MOD_h5fclose_f' /home/bharat/stochastic/main.f90:157: undefined reference to `__h5lib_MOD_h5close_f' collect2: error: ld returned 1 exit status make: *** [main] Error 1 时发生。我确保符号链接指向正确的位置。将libhdf5-fortran添加到同一个lib目录也无法解决问题。库和符号链接具有读取和执行权限。我看不出问题出在哪里。

rpath

这在-rw-r--r-- 1 root root 5752246 May 23 03:24 libhdf5.a -rw-r--r-- 1 root root 431820 May 23 03:24 libhdf5_fortran.a -rwxr-xr-x 1 root root 1035 May 23 03:24 libhdf5_fortran.la* lrwxrwxrwx 1 root root 25 May 23 03:24 libhdf5_fortran.so -> libhdf5_fortran.so.10.0.0* lrwxrwxrwx 1 root root 25 May 23 03:24 libhdf5_fortran.so.10 -> libhdf5_fortran.so.10.0.0* -rwxr-xr-x 1 root root 355600 May 23 03:24 libhdf5_fortran.so.10.0.0* -rw-r--r-- 1 root root 211088 May 23 03:24 libhdf5_hl.a -rw-r--r-- 1 root root 150528 May 23 03:24 libhdf5hl_fortran.a -rwxr-xr-x 1 root root 1126 May 23 03:24 libhdf5hl_fortran.la* lrwxrwxrwx 1 root root 27 May 23 03:24 libhdf5hl_fortran.so -> libhdf5hl_fortran.so.10.0.0* lrwxrwxrwx 1 root root 27 May 23 03:24 libhdf5hl_fortran.so.10 -> libhdf5hl_fortran.so.10.0.0* -rwxr-xr-x 1 root root 112246 May 23 03:24 libhdf5hl_fortran.so.10.0.0* -rwxr-xr-x 1 root root 1000 May 23 03:24 libhdf5_hl.la* lrwxrwxrwx 1 root root 20 May 23 03:24 libhdf5_hl.so -> libhdf5_hl.so.10.0.0* lrwxrwxrwx 1 root root 20 May 23 03:24 libhdf5_hl.so.10 -> libhdf5_hl.so.10.0.0* -rwxr-xr-x 1 root root 148227 May 23 03:24 libhdf5_hl.so.10.0.0* -rwxr-xr-x 1 root root 946 May 23 03:24 libhdf5.la* -rw-r--r-- 1 root root 3266 May 23 03:24 libhdf5.settings lrwxrwxrwx 1 root root 17 May 23 03:24 libhdf5.so -> libhdf5.so.10.0.0* lrwxrwxrwx 1 root root 17 May 23 03:24 libhdf5.so.10 -> libhdf5.so.10.0.0* -rwxr-xr-x 1 root root 3133678 May 23 03:24 libhdf5.so.10.0.0* -libhdf5_fortran所在的另外两个系统中运行良好(所以我没有指定库路径);这些系统中的gfortran版本是(RH)4.8.3,而ld版本是2.23.2。
在当前系统中,gfortran是4.7.2(ubuntu),ld是2.22.90。 我不认为这是过时版本的问题。

1 个答案:

答案 0 :(得分:1)

你应该试试

main: main.o param.o dmotifs.o ssa.o
    $(FC) $^ $(LFLAGS) $(LIBS) -o main 

而不是

main: main.o param.o dmotifs.o ssa.o
    $(FC) $(LFLAGS) $(LIBS) -o main $^

因为链接器标志应该是最后的,否则它将静默地丢弃库,因为在处理标志时没有未解析的符号。