“未定义的参考”尝试使用Ifort编译具有外部依赖关系的Fortran程序时的错误
我正在使用以下命令来编译我的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.1
和libhdf5_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软件包管理器安装这些软件包。 hdf5
从tar.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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论