HDF5 windows编译 release版本、Debug版本

article/2025/9/12 19:22:45

由于最近急需的一个项目,需要hdf5库,误打误撞,编译成功。特此记录

1、下载源代码

官网下载地址:https://portal.hdfgroup.org/display/support/HDF5+1.12.2#files

找到如下地址,本人电脑有cmake软件,我下载了Cmake版本和源代码版本同时进行了,事实上我也下载了源码进行cmake手工编译,但是不如直接下载CMake版本的来的方便,所以这里我直接记录了Cmake版本的编译方法
在这里插入图片描述

如果下载不了,可以通过该链接进行下载

2、编译步骤:

如果不想看怎么编译,可以从这里下载我编译好的库
1、下载解压(注意路径,最好不要有中文路径,个人习惯)
2、进入文件夹后,如下图
在这里插入图片描述
3、该文件夹下有很多批处理文件,由于我电脑上有VS2017,所以我默认使用“build-VS2017-64_debug.bat”文件。

4、点击“build-VS2017-64.bat”以管理员方式运行,剩下就是看着cmd窗口不断的编译、等待…

5、无尽等待完后,就是查看成果了。该编译的成果就在“build-VS2017-64.bat”同级文件夹的“HDF5-1.12.2-win64.zip”压缩包(我是后面改名:HDF5-1.12.2-win64_release.zip,由于这个bat处理里面是只编译Release版本,Debug版本需要再单独编译,我是在后面配置测试才发现这个问题,这里我就不记录怎么走的弯路了)
在这里插入图片描述

6、Debug版本编译:更改“HDF5-1.12.2-win64.zip”为“HDF5-1.12.2-win64_release.zip”,避免编译debug版本的时候被覆盖了。复制一份“build-VS2017-64.bat”改名为“build-VS2017-64_debug.bat”,用notepad打开后,将“Release”更换为“Debug”即可
在这里插入图片描述
7、点击“build-VS2017-64_debug.bat”以管理员方式运行,剩下就是看着cmd窗口不断的编译、等待…
8、更改“HDF5-1.12.2-win64.zip”为“HDF5-1.12.2-win64_debug.zip”,将debug压缩包和release压缩包解压,然后进行“bin”文件夹、“lib”文件夹合并即可。

Debug lib文件加载下面即可:

libaec_D.lib
libhdf5_D.lib
libhdf5_cpp_D.lib
libhdf5_hl_D.lib
libhdf5_hl_cpp_D.lib
libhdf5_tools_D.lib
libszaec_D.lib
libz_D.lib

3、测试代码

Create H5文件测试代码:
该代码

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ** Copyright © 2020 Wei Wang.						                           ** Created by WW on 2020/01/26.	                                               ** All rights reserved.							                               **	                                                                           ** This example illustrates how to create a dataset that is a 4 x 6 array.     ** Reference: HDF5 Tutorial (https://portal.hdfgroup.org/display/HDF5/HDF5)    ** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *///// h5cpp_creating.cpp// CPP//#include <iostream>
#include <string>
#include "H5Cpp.h"#ifndef _H5_NO_NAMESPACE_
using namespace H5;
#ifndef _H5_NO_STD_
using std::cout;
using std::endl;
#endif /* _H5_NO_STD_ */        
#endif /* _H5_NO_NAMESPACE_ */#define PI 3.1415926535/**  Define the names of HDF5 file, groups, datasets, and attributes.*  Use H5::H5std_string for name strings.*/
const H5std_string FILE_NAME("h5cpp_example.hdf5");
const H5std_string GROUP_NAME("group1");
const H5std_string DATASET_NAME("dset");
const H5std_string ATTR_NAME1("myAttr1");
const H5std_string ATTR_NAME2("myAttr2");const int DIM0 = 4;       // dataset dimensions
const int DIM1 = 6;
const int RANK = 2;int main(int argc, char **argv)
{// Try block to detect exceptions raised by any of the calls inside it.try{/** Turn off the auto-printing when failure occurs so that we can* handle the errors appropriately.*/Exception::dontPrint();/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */double data[DIM0][DIM1];	    // buffer for data to writefor (int i = 0; i < DIM0; i++)for (int j = 0; j < DIM1; j++)data[i][j] = (i + 1) * PI + j;// Create a new file using the default property lists.// H5::H5F_ACC_TRUNC : create a new file or overwrite an existing file.H5File file(FILE_NAME, H5F_ACC_TRUNC);// Create a group under root '/'.Group group(file.createGroup(GROUP_NAME));// Use H5::hsize_t (similar to int) for dimensions.hsize_t dims[RANK];               // dataset dimensionsdims[0] = DIM0;dims[1] = DIM1;// Create the dataspace for a dataset first.DataSpace dataspace(RANK, dims);// Create the dataset under group with specified dataspace.      DataSet dataset = group.createDataSet(DATASET_NAME, PredType::NATIVE_DOUBLE, dataspace);// Write data in buffer to dataset.dataset.write(data, PredType::NATIVE_DOUBLE);/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */int attr1_data[2] = { 100, 200 };          // buffer for attribute data to wirtehsize_t attr1_dims[1] = { 2 };             // attribute dimension, rank = 1// Create the dataspace for an attribute first.DataSpace attr1_dataspace(1, attr1_dims);         // rank = 1// Create the attribute of dataset with specified dataspace.Attribute attribute1 = dataset.createAttribute(ATTR_NAME1, PredType::STD_I32BE, attr1_dataspace);// Write data in buffer to attribute.attribute1.write(PredType::NATIVE_INT, attr1_data);/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *//* String Data */char attr2_data[30];    // buffer for attribute data to wirte sprintf(attr2_data, "hello, world!\nAuthor: Wei Wang");hsize_t attr2_dims[1] = { 30 };       // attribute dimension, rank = 1// Create the dataspace for an attribute first.DataSpace attr2_dataspace(1, attr2_dims);       // rank = 1// Create the attribute of dataset with specified dataspace.Attribute attribute2 = dataset.createAttribute(ATTR_NAME2, PredType::NATIVE_CHAR, attr2_dataspace);// Write data in buffer to attribute.attribute2.write(PredType::NATIVE_CHAR, attr2_data);/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */// Save and exit the group.group.close();// Save and exit the file.file.close();/* h5cpp_example.hdf5 file structure* +-- '/'* |   +-- group 'group1'* |   |   +-- dataset 'dset'* |   |   |   +-- attribute 'myAttr1'* |   |   |   +-- attribute 'myAttr2'* |   |   |* |   |* |*/}  // end of try block// Catch failure caused by the H5File operations.catch (FileIException error){error.printErrorStack();return -1;}// Catch failure caused by the DataSet operations.catch (DataSetIException error){error.printErrorStack();return -1;}// Catch failure caused by the DataSpace operations.catch (DataSpaceIException error){error.printErrorStack();return -1;}return 0;  // successfully terminated}

H5 Reading测试代码,里面一段代码需要改一下才可以用,我用Create h5代码测试可以了就没有继续改了

double data_out[dims[0]][dims[1]];  
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ** Copyright © 2020 Wei Wang.                                                  ** Created by WW on 2020/01/26.                                                ** All rights reserved.                                                        **                                                                             ** This example illustrates how to read and edit an existing dataset.          ** Reference: HDF5 Tutorial (https://portal.hdfgroup.org/display/HDF5/HDF5)    ** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *///// h5cpp_reading.cpp// CPP//#include <iostream>
#include <string>
#include "H5Cpp.h"#ifndef _H5_NO_NAMESPACE_
using namespace H5;
#ifndef _H5_NO_STD_
using std::cout;
using std::endl;
#endif /* _H5_NO_STD_ */        
#endif /* _H5_NO_NAMESPACE_ *//**  Define the names of HDF5 file, groups, datasets, and attributes.*  Use H5::H5std_string for name strings.*/
const H5std_string FILE_NAME("h5cpp_example.hdf5");
const H5std_string GROUP_NAME("group1");
const H5std_string DATASET_NAME("dset");
const H5std_string ATTR_NAME("myAttr2");int main(int argc, char **argv)
{// Try block to detect exceptions raised by any of the calls inside it.try{/** Turn off the auto-printing when failure occurs so that we can* handle the errors appropriately*/Exception::dontPrint();/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *//* HOW TO DELETING A DATASET! *//*// Open an existing file.// H5::H5F_ACC_RDWR : read or edit an existing file.H5File file_d(FILE_NAME, H5F_ACC_RDWR);// Open an existing group.Group group_d = file_d.openGroup(GROUP_NAME);// Use H5::H5Ldelete to delete an existing dataset.int result = H5Ldelete(group_d.getId(), DATASET_NAME.c_str(), H5P_DEFAULT);// String.c_str() convert "string" to "const char *".cout << result << endl;// Non-negtive: successfully delete;// Otherwise: fail.// Save and exit the group.group_d.close();// Save and exit the file.file_d.close();// Important! The two close()s above can't be omitted!// Otherwise, the deleting behavior won't be saved to file.*//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */// Open an existing file.// H5::H5F_ACC_RDWR : read or edit an existing file.H5File file(FILE_NAME, H5F_ACC_RDWR);// Open an existing group of the file.Group group = file.openGroup(GROUP_NAME);// Open an existing dataset of the group.DataSet dataset = group.openDataSet(DATASET_NAME);// Get the dataspace of the dataset.DataSpace filespace = dataset.getSpace();// Get the rank of the dataset.int rank = filespace.getSimpleExtentNdims();// Use H5::hsize_t (similar to int) for dimensions//hsize_t dims[rank];        // dataset dimensionshsize_t* dims=new hsize_t[rank];        // dataset dimensions// Get the dimensions of the dataset.rank = filespace.getSimpleExtentDims(dims);cout << DATASET_NAME << " rank = " << rank << ", dimensions "<< dims[0] << " x "<< dims[1] << endl;// Dataspace for data read from file.DataSpace myspace(rank, dims);//下面这个代码定义有问题,不能使用变量当作常数这么定义,需要改一下double data_out[dims[0]][dims[1]];      // buffer for data read from file//=======================================================================================================//double** data_out=new double*[dims[0]];      // 这一段代码改写可能存在问题//for (int id = 0; id < dims[0]; id++)//{//	data_out[id] = new double[dims[1]];//}//=======================================================================================================// Read data from file to buffer.dataset.read(data_out, PredType::NATIVE_DOUBLE, myspace, filespace);for (int i = 0; i < dims[0]; i++){for (int j = 0; j < dims[1]; j++)cout << data_out[i][j] << " ";cout << endl;}/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */// Read the attribute of the dataset.cout << endl;// Open an existing attribute of the dataset.Attribute attr = dataset.openAttribute(ATTR_NAME);// Get the dataspace of the attribute.DataSpace attr_space = attr.getSpace();// Get the rank of the attribute.int attr_rank = attr_space.getSimpleExtentNdims();// Use H5::hsize_t (similar to int) for dimensions.//hsize_t attr_dims[attr_rank];       // attribute dimensionshsize_t* attr_dims=new hsize_t[attr_rank];       //改写上面一句代码// Get the dimension of the attribute.attr_rank = attr_space.getSimpleExtentDims(attr_dims);cout << ATTR_NAME << " rank = " << attr_rank << ", dimensions " << attr_dims[0] << endl;//char attr_data_out[attr_dims[0]];   // buffer for attribute data read from filechar* attr_data_out=new char[attr_dims[0]];   // buffer for attribute data read from file// Read attribute data from file to buffer.  attr.read(PredType::NATIVE_CHAR, attr_data_out);cout << attr_data_out << endl;/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */// Save and exit the group.group.close();// Save and exit the file.file.close();}  // end of try block// Catch failure caused by the H5File operations.catch (FileIException error){error.printErrorStack();return -1;}// Catch failure caused by the DataSet operations.catch (DataSetIException error){error.printErrorStack();return -1;}// Catch failure caused by the DataSpace operations.catch (DataSpaceIException error){error.printErrorStack();return -1;}return 0;  // successfully terminated}

http://chatgpt.dhexx.cn/article/tmZW1I9h.shtml

相关文章

[HDF5]如何使用CMake一起编译自己的代码和HDF5库

以一个实际项目来举例 目录 一.目录结构 二.CMakeLists.txt内容 三.执行CMakeLists命令 一.目录结构 1.build放CMake执行后生成的所有的内容&#xff0c;包括最后的工程或可执行文件等; 2.include放工程的头文件&#xff0c;以及HDF5的头文件&#xff0c;可以直接把HDF5中…

HDF5简介

1、介绍 HDF 是用于存储和分发科学数据的一种自我描述、多对象文件格式。HDF 是由美国国家超级计算应用中心&#xff08;NCSA&#xff09;创建的&#xff0c;以满足不同群体的科学家在不同工程项目领域之需要。HDF 可以表示出科学数据存储和分布的许多必要条件。HDF 被设计为&…

HDF5数据的打包与使用(以图像数据为例)

文章目录 1 什么是HDF5数据2 HDF5数据格式的生成3 HDF5数据的查看 注&#xff1a;此篇内容主要作为使用PyTorch构建GAN生成对抗网络博客中&#xff0c;HDF5数据类型的补充介绍。 1 什么是HDF5数据 HDF5 数据是存储在一种名为 Hierarchical Data Format version 5 (HDF5) 的二进…

HDF5-简介

HDF&#xff08;Hierarchical Data Format&#xff09;是一种设计用于存储和组织大量数据的文件格式&#xff0c;最开始由美国国家超算中心研发&#xff0c;后来由一个非盈利组织HDF Group支持.HDF支持多种商业及非商业的软件平台&#xff0c;包括MATLAB、Java、Python、R和Jul…

HDF5到底是什么

HDF5到底是什么 《Python和HDF 5大数据应用》——1.2 HDF5到底是什么-阿里云开发者社区 1.2 HDF5到底是什么 HDF5是一种存储相同类型数值的大数组的机制&#xff0c;适用于可被层次性组织且数据集需要被元数据标记的数据模型。 它跟SQL风格的关系型数据库区别相当大&…

HDF5快速上手全攻略

HDF5快速上手全攻略 1. HDF5简介 Hierarchical Data Format(HDF)是一种针对大量数据进行组织和存储的文件格式。经历了20多年的发展&#xff0c;HDF格式的最新版本是HDF5&#xff0c;它包含了数据模型&#xff0c;库&#xff0c;和文件格式标准。以其便捷有效&#xff0c;移植…

Macbook Pro笔记本双系统MacOS和Windows切换默认启动

一、开机切换 开机时&#xff0c;按住option键不要动&#xff0c;等待Macbook Pro出现以下界面&#xff0c;选择你想开机的系统即可。 &#xff08;BootCamp就是Windows&#xff09; 二、默认切换&#xff0c;这里分两种情况 1&#xff09;默认MacOS开机&#xff0c;切换到W…

笔记本双系统Windows10/Deepin15.11体验记录【Deepin15.11体验记录】第一天

笔记本双系统Windows10/Deepin15.11体验记录 【Deepin15.11体验记录】第一天 今天我试着将笔记本安装了第二个系统&#xff08;基于Linux的Deepin15.11系统&#xff09;&#xff0c;非常成功。之前接触过虚拟机里的Redhat Linux&#xff0c;但是那种是多年前的版本&#xff0…

华硕ROG枪神配置Ubuntu双系统

华硕ROG枪神配置Ubuntu双系统 最近笔记本刚到&#xff0c;华硕ROG枪神6plus&#xff0c;12900HRTX3060&#xff08;没错&#xff0c;最低配&#xff09;&#xff0c;想着配置一下Ubuntu系统&#xff0c; 但是网上没有相关参考教程&#xff0c;我自己在下面步骤4设置硬盘启动方…

各笔记本安装双系统遇到的问题

目录 联想Y9000P2023款安装ubuntu出现efi usb device has been blocked by the current security policy导致无法进入安装目录 ​编辑 Thinkpad p15 gen1安装双系统遇到的问题 回忆安装xubuntu20.04LTS出现的问题和解决办法&#xff1a; Thinkpad p15 gen1 合盖关机的设置…

苹果笔记本安装Win10双系统+分区教程《原创完整精华版》

苹果笔记本安装Win10双系统分区教程《完整精华版》 写在前面&#xff1a;1.此款笔记本已测试支持安装Win10 1909版本、1903版本。建议安装比较新的Win10版本。2.此教程是先装Win10系统&#xff0c;再进苹果系统分区。最初我想是先分区&#xff0c;再安装&#xff0c;可无论如何…

红米笔记本linux系统版本,小米笔记本安装Win10+Ubuntu16.04 LTS 双系统

安装Win10+Ubuntu16.04 LTS 双系统(持续更新:Ubuntu安装N卡驱动,续航+2小时) 原贴:http://bbs.xiaomi.cn/t-13391152 (来自小米社区玩机教程) 完成图: 目标:安装Win10 + Ubuntu16.04 LTS 双系统 电脑:小米Air 13.3 高配版 工具: 硬件:U盘(2G就够,镜像包解压后文件大小为1.…

dell笔记本安装Ubuntu20.04双系统+cuckoo布谷鸟沙箱

windows下安装Ubuntu20.04双系统cuckoo布谷鸟沙箱 本篇文章主要是在Ubuntu20.04系统上搭建cuckoo沙箱&#xff0c;之前曾尝试在VMware虚拟机里建立Ubuntu&#xff0c;然后再在Ubuntu虚拟机里安装vbox虚拟机&#xff0c;然后搭建沙箱&#xff0c;但是这种虚拟机里安装虚拟机的想…

戴尔笔记本安装双系统(win10+ubuntu20.04)避坑记录

戴尔笔记本安装双系统&#xff08;win10ubuntu20.04&#xff09;避坑记录 从最开始DIY到用联想服务器&#xff0c;再到现在的戴尔某笔记本&#xff0c;一路走来都是从csdn上的各路大神帖子上学习安装&#xff0c;帮助很大&#xff0c;避免了很多弯路&#xff1b;但也有一些不太…

华为笔记本linux双系统,真的有必要吗?华为笔记本搭载双系统

近段时间有消息称&#xff0c;华为将会推出一款12.9寸笔记本电脑将会采用PC、平板二合一的设计&#xff0c;同时搭载Intel平台并且支持Windows 10与Android双系统&#xff0c;日常状态下是运行Windows 10的笔记本电脑&#xff0c;而将键盘拆开后则会变为一台Android平板&#x…

苹果电脑装双系统利弊有哪些

很多人购买了苹果电脑以后,很多用户使用MAC系统还是很不习惯,都担心许多Windows软件不能使用了。那么苹果电脑装双系统有什么好处和坏处呢?很多用户都不清楚苹果电脑装双系统利弊在哪&#xff0c;今天&#xff0c;小编就把苹果电脑装双系统利弊有哪些的介绍分享给大家。 更多…

小米笔记本双固态硬盘安装win10+ubantu20双系统 实录

一.基本信息 电脑型号&#xff1a;小米笔记本Pro15.6 显卡型号&#xff1a;NVIDIA GeForce GTX 1050 Max-Q 原装固态硬盘&#xff1a;英特尔 SSDPEKNW010T8 容量&#xff1a;1024G 加装固态硬盘&#xff1a;三星860 EVO M.2接口&#xff08;SATA总线&#xff09; 容量&a…

笔记本双系统安装Ubuntu 20.04.3 LTS没有WIFI的解决方法

笔记本双系统安装Ubuntu 20.04.3 LTS没有WIFI 解决方法 最近使用华硕笔记本安装双系统&#xff08;win10 ubuntu20.04.3 LTS&#xff09;&#xff0c;安装好之后发现Ubuntu系统的设置里面没有wifi功能&#xff0c;就无法连接WIFI&#xff0c;只能使用有线网来上网。弄了好久终…

双系统笔记本 android,电脑安装双系统 微软 安卓 实现一机多用

在windows系统的电脑上再安装一个安卓系统&#xff0c;实现双系统自由切换。在windows系统中操作运行原来的所有程序&#xff0c;干该干的事&#xff1b;在安卓系统中运行安卓软件&#xff0c;比如 安装游戏APP玩手游、安装“电视家”APP取代机顶盒、安装网络教育APP上网课&…

双系统笔记本 android,安卓不止平板有 教你使用笔记本装安卓,和WINDOWS一起双系统亦可以的哦!(图解)...

随着新iPad的发售&#xff0c;苹果CEO蒂姆库克发表了“后PC时代”言论都表明平板市场的迅速扩张。不过现在我们在日常工作中还是离不开笔记本电脑的。通过开发移植&#xff0c;笔记本现在也可以安装只有移动设备才能使用的安卓系统&#xff0c;并实现大部分功能&#xff0c;同时…