gpt4 book ai didi

linux - ld 找不到现有的库

转载 作者:太空狗 更新时间:2023-10-29 12:30:01 27 4
gpt4 key购买 nike

我正在编译需要安装在本地目录中的 hdf5 库的 Fortran 代码。这是我的生成文件:

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

在链接期间我得到这个错误:

/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

这通常发生在未指定 hdf-fortran 库 libhdf5-fortran 时。我确保符号链接(symbolic link)指向正确的位置。将 rpath 添加到同一个 lib 目录也不能解决问题。库和符号链接(symbolic link)具有读取和执行权限。我看不出问题出在哪里。

-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 位于 /lib64 的其他两个系统中运行良好(因此我不必指定库路径);这些系统中的 gfortran 版本是 (RH) 4.8.3,ld 版本是 2.23.2。
在当前系统中,gfortran 是 4.7.2 (ubuntu),ld 是 2.22.90。我不认为这是过时版本的问题。

最佳答案

你应该试试

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 $^

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

关于linux - ld 找不到现有的库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30397233/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com