“未定义的参考”尝试使用Ifort编译具有外部依赖关系的Fortran程序时的错误

发布于 2025-01-28 13:34:18 字数 2909 浏览 3 评论 0原文

我正在使用以下命令来编译我的fortran程序,这是我的hdf5 h5fc命令的最后一行,我的ubuntu 20.04.4 lts x86_64 Machine(添加newlines的可透明度):

<path_to_my_intel_oneapi_folder>/compiler/2022.0.2/linux/bin/intel64/ifort -shlib 
-I<path_to_my_hdf5_1.12.2>/include 
-L<path_to_my_hdf5_1.12.2>/lib 
-lhdf5_fortran 
-lhdf5 
-I<path_to_my_mpich_4.0.2>/include 
-L<path_to_my_mpich_4.0.2>/lib 
-lmpifort -Wl,-rpath -Wl,<path_to_my_mpich_4.0.2>/lib 
-lmpi <path_to_my_intel_oneapi_folder>/compiler/2022.0.2/linux/bin/intel64/ifort

我用cmake而不是autotools ,它具有由此产生的安装略有差异,但仍应在我当前的机器上工作。 成功编译后链接会导致大量未定义的参考错误,例如:

ld: /path_to_my_file/my_file.o: in function `hdf5_utilities_mp_hdf5_openfile_':
my_file.f90:(.text+0xcbf8): undefined reference to `h5global_mp_h5p_file_access_f_'
ld: my_file.f90:(.text+0xcc0a): undefined reference to `h5p_mp_h5pcreate_f_'
ld: my_file.f90:(.text+0xcc2a): undefined reference to `h5global_mp_h5f_acc_trunc_f_'
ld: my_file.f90:(.text+0xcc45): undefined reference to `h5f_mp_h5fcreate_f_'
ld: my_file.f90:(.text+0xcc63): undefined reference to `h5global_mp_h5f_acc_rdwr_f_'
ld: my_file.f90:(.text+0xcc79): undefined reference to `h5f_mp_h5fopen_f_'
ld: my_file.f90:(.text+0xcc93): undefined reference to `h5global_mp_h5f_acc_rdonly_f_'
ld: my_file.f90:(.text+0xcca9): undefined reference to `h5f_mp_h5fopen_f_'
ld: my_file.f90:(.text+0xccc4): undefined reference to `h5p_mp_h5pclose_f_'

PATH &lt; path_to_my_my_hdf5_1.1.1.12.2&gt;/lib,在<<代码> -l <​​/code>上述的标志命令,包含文件libhdf5_fortran.so.so.200.1.1libhdf5_fortran.a包含无法链接的HDF函数的引用,例如h5global_mp_h5p_file_access_f _。 我假设这些错误与以下命令有关,该命令位于my_file.f90的其他文件中,使用:

module HDF5_utilities
  use HDF5
...
integer(HID_T) function HDF5_openFile(fileName,mode,parallel)
  ...
  integer(HID_T) :: plist_id
  integer :: hdferr
  call H5Pcreate_f(H5P_FILE_ACCESS_F, plist_id, hdferr)
  ...

此问题已经开始发生,因为我创建了一个新的ifort HDF5 < /code>在我的计算机上设置,并且我的源文件在此之前没有任何问题,因此我认为这与当前在我的系统上安装了HDF5的方式有关。我用cmake和使用的mpich作为依赖项安装了HDF5,并且正在使用 spack软件包管理器安装这些软件包。 hdf5tar.gz文件从此源并使用 intel oneapi软件包

I am using the following command to compile my fortran program, which is the last line of the result of the hdf5 h5fc command on my Ubuntu 20.04.4 LTS x86_64 machine (added newlines for legibility):

<path_to_my_intel_oneapi_folder>/compiler/2022.0.2/linux/bin/intel64/ifort -shlib 
-I<path_to_my_hdf5_1.12.2>/include 
-L<path_to_my_hdf5_1.12.2>/lib 
-lhdf5_fortran 
-lhdf5 
-I<path_to_my_mpich_4.0.2>/include 
-L<path_to_my_mpich_4.0.2>/lib 
-lmpifort -Wl,-rpath -Wl,<path_to_my_mpich_4.0.2>/lib 
-lmpi <path_to_my_intel_oneapi_folder>/compiler/2022.0.2/linux/bin/intel64/ifort

I built hdf5 with cmake instead of autotools, which has slight differences in the resulting installation but should still work on my current machine.
Linking after successfully compiling results in a large number of undefined reference errors, such as following:

ld: /path_to_my_file/my_file.o: in function `hdf5_utilities_mp_hdf5_openfile_':
my_file.f90:(.text+0xcbf8): undefined reference to `h5global_mp_h5p_file_access_f_'
ld: my_file.f90:(.text+0xcc0a): undefined reference to `h5p_mp_h5pcreate_f_'
ld: my_file.f90:(.text+0xcc2a): undefined reference to `h5global_mp_h5f_acc_trunc_f_'
ld: my_file.f90:(.text+0xcc45): undefined reference to `h5f_mp_h5fcreate_f_'
ld: my_file.f90:(.text+0xcc63): undefined reference to `h5global_mp_h5f_acc_rdwr_f_'
ld: my_file.f90:(.text+0xcc79): undefined reference to `h5f_mp_h5fopen_f_'
ld: my_file.f90:(.text+0xcc93): undefined reference to `h5global_mp_h5f_acc_rdonly_f_'
ld: my_file.f90:(.text+0xcca9): undefined reference to `h5f_mp_h5fopen_f_'
ld: my_file.f90:(.text+0xccc4): undefined reference to `h5p_mp_h5pclose_f_'

The path <path_to_my_hdf5_1.12.2>/lib, which is specified in the -L flag of the abovementioned ifort command, contains the files libhdf5_fortran.so.200.1.1 and libhdf5_fortran.a which contain the references to the hdf functions that cannot be linked, such as h5global_mp_h5p_file_access_f_.
I assume that those errors are related to the following command, which is located in a different file that my_file.f90 makes use of:

module HDF5_utilities
  use HDF5
...
integer(HID_T) function HDF5_openFile(fileName,mode,parallel)
  ...
  integer(HID_T) :: plist_id
  integer :: hdferr
  call H5Pcreate_f(H5P_FILE_ACCESS_F, plist_id, hdferr)
  ...

This problem has started occuring since I created a new ifort hdf5 setup on my machine and my source files had no issues compiling prior to this, so I assume this is related to the way hdf5 is currently installed on my system. I installed hdf5 with cmake and used mpich as a dependency and am am using the spack package manager to install those packages. hdf5 is fetched from the tar.gz file from this source and compiled using the intel compiler from the intel oneapi package.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文