如何用HDF5源代码编译c程序?
How to compile c program with HDF5 source code?
我有特定的要求,我想编译和执行一些具有 HDF5 依赖项的代码。
我不想使用 hdf5 compiler
,但我想编译 HDF5 源代码。
我对如何将 HDF5 link 加入我的 C 程序还很陌生。请详细解释如何操作,以便我可以使用 c 编译器和 linking 从 here.
下载的源文件来执行该程序
示例 C 程序 -
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* Copyright by the Board of Trustees of the University of Illinois. *
* All rights reserved. *
* *
* This file is part of HDF5. The full HDF5 copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the files COPYING and Copyright.html. COPYING can be found at the root *
* of the source code distribution tree; Copyright.html can be found at the *
* root level of an installed copy of the electronic HDF5 document set and *
* is linked from the top-level documents page. It can also be found at *
* http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
* access to either file, you may request a copy from help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*
* This example illustrates how to create a dataset that is a 4 x 6
* array. It is used in the HDF5 Tutorial.
*/
#include "hdf5.h"
#define FILE "dset.h5"
int main() {
hid_t file_id, dataset_id, dataspace_id; /* identifiers */
hsize_t dims[2];
herr_t status;
/* Create a new file using default properties. */
file_id = H5Fcreate(FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
/* Create the data space for the dataset. */
dims[0] = 4;
dims[1] = 6;
dataspace_id = H5Screate_simple(2, dims, NULL);
/* Create the dataset. */
dataset_id = H5Dcreate2(file_id, "/dset", H5T_STD_I32BE, dataspace_id,
H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
/* End access to the dataset and release resources used by it. */
status = H5Dclose(dataset_id);
/* Terminate access to the data space. */
status = H5Sclose(dataspace_id);
/* Close the file. */
status = H5Fclose(file_id);
}
编译时需要-I
标志指向HDF5的include目录。对于系统安装,它通常是 /usr/include
,但根据 HDF5 是串行安装还是并行安装、32/64 位等,会有很多变化。对于 linking -L
和 -l
标志是重要的标志。 -L
应该指向包含 HDF5 库的 .so
、.dll
或 .dylib
文件的目录(同样,可以有变化)并且 -l
只是给出库名称 -lhdf5
和其他名称(我相信 -lz
和 -lm
几乎总是被使用)。如果使用高级库,需要-lhdf5_hl
。
检查这些标志的最简单方法是调用
h5cc -show
这将列出所有内容。
PS:可以一步编译和link(从.c
到可执行文件)或者先编译(.c
到.o
) 然后 link (.o
到可执行文件)。在第一种情况下,需要所有 -I
、-L
和 -l
标志。
我有特定的要求,我想编译和执行一些具有 HDF5 依赖项的代码。
我不想使用 hdf5 compiler
,但我想编译 HDF5 源代码。
我对如何将 HDF5 link 加入我的 C 程序还很陌生。请详细解释如何操作,以便我可以使用 c 编译器和 linking 从 here.
下载的源文件来执行该程序示例 C 程序 -
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* Copyright by the Board of Trustees of the University of Illinois. *
* All rights reserved. *
* *
* This file is part of HDF5. The full HDF5 copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the files COPYING and Copyright.html. COPYING can be found at the root *
* of the source code distribution tree; Copyright.html can be found at the *
* root level of an installed copy of the electronic HDF5 document set and *
* is linked from the top-level documents page. It can also be found at *
* http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
* access to either file, you may request a copy from help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*
* This example illustrates how to create a dataset that is a 4 x 6
* array. It is used in the HDF5 Tutorial.
*/
#include "hdf5.h"
#define FILE "dset.h5"
int main() {
hid_t file_id, dataset_id, dataspace_id; /* identifiers */
hsize_t dims[2];
herr_t status;
/* Create a new file using default properties. */
file_id = H5Fcreate(FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
/* Create the data space for the dataset. */
dims[0] = 4;
dims[1] = 6;
dataspace_id = H5Screate_simple(2, dims, NULL);
/* Create the dataset. */
dataset_id = H5Dcreate2(file_id, "/dset", H5T_STD_I32BE, dataspace_id,
H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
/* End access to the dataset and release resources used by it. */
status = H5Dclose(dataset_id);
/* Terminate access to the data space. */
status = H5Sclose(dataspace_id);
/* Close the file. */
status = H5Fclose(file_id);
}
编译时需要-I
标志指向HDF5的include目录。对于系统安装,它通常是 /usr/include
,但根据 HDF5 是串行安装还是并行安装、32/64 位等,会有很多变化。对于 linking -L
和 -l
标志是重要的标志。 -L
应该指向包含 HDF5 库的 .so
、.dll
或 .dylib
文件的目录(同样,可以有变化)并且 -l
只是给出库名称 -lhdf5
和其他名称(我相信 -lz
和 -lm
几乎总是被使用)。如果使用高级库,需要-lhdf5_hl
。
检查这些标志的最简单方法是调用
h5cc -show
这将列出所有内容。
PS:可以一步编译和link(从.c
到可执行文件)或者先编译(.c
到.o
) 然后 link (.o
到可执行文件)。在第一种情况下,需要所有 -I
、-L
和 -l
标志。