HDF5 windows编译 release版本、Debug版本

2023-11-15

由于最近急需的一个项目,需要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 write

		for (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 dimensions
		dims[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 wirte

		hsize_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 dimensions
		hsize_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 dimensions
		hsize_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 file
		char* 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

}

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

HDF5 windows编译 release版本、Debug版本 的相关文章

随机推荐

  • 2022电赛E题(不使用K210)软硬件方案

    请各位客观移步小黄鱼搜索DreamChuan用户 拍下链接即可获取全部软硬件方案哦 物美价廉 2022电赛E题声源定位 不使用K210相关软硬件 使用MAX9814麦克风加stm32F103ZET6加28BYJ48步进电机方案 部分代码开源
  • log4j 配置文件详解

    log4j logger stdout debug 灵活设置日志格式 log4j appender stdout layout org apache log4j PatternLayout 文件 log4j appender stdout
  • 阅读-MTCNN

    原始数据 人脸数据集WIDER FACE 该数据集仅提供了大量的人脸边框定位数据 如果使用wider face的 wider face train mat 注解文件需要转换成txt格式的 我这里用h5py写了个 转换脚本 这里我提供一个已经
  • Python实现输入电影名字自动生成豆瓣评论词云图(带GUI界面)小程序

    Python实现输入电影名字自动生成豆瓣评论词云图 带GUI界面 小程序 一 项目背景 电影逐渐成为人们生活的不可或缺的一部分 而了解一部电影的可以通过电影评分与大众推荐度 但以上的方式都太过于片面 了解一部电影的方法是通过已经观看完电影的
  • Windows CE嵌入式导航系统研究(应用程序相关)

    1 1 1 TCPMP多媒体播放器 本系统中采用的多媒体播放器是TCPMP TCPMP播放器播放速度很快且支持多达几十中多媒体格式 TCPMP开源项目 同时支持Windows CE操作系统 而且提供很好的扩展性 例如需要重新编写TCPMP界
  • 给定一个非负整数 num,反复将各个位上的数字相加,直到结果为一位数。返回这个结果。

    258 各位相加 难度简单475 给定一个非负整数 num 反复将各个位上的数字相加 直到结果为一位数 返回这个结果 示例 1 输入 num 38 输出 2 解释 各位相加的过程为 38 gt 3 8 gt 11 11 gt 1 1 gt
  • 大文件上传服务器jvm调优,JVM性能调优的6大步骤,及关键调优参数详解

    JVM内存调优 对JVM内存的系统级的调优主要的目的是减小GC的频率和Full GC的次数 算法 1 Full GC编程 会对整个堆进行整理 包括Young Tenured和Perm Full GC由于须要对整个堆进行回收 因此比较慢 所以
  • 【Flutter 2-11】Flutter手把手教程UI布局和Widget——列表ListView

    作者 弗拉德 来源 弗拉德 公众号 fulade me ListView ListView是在移动端非常常见的控件 在大多数的展示场景中都离不开ListView 在Flutter中对ListView的封装也非常好 简单几行代码就可以满足我们
  • 马尔萨斯 ( Malthus)人口指数增长模型&Logistic 模型

    3 要求与任务 从 1790 1990 年间美国每隔 10 年的人口记录如下表所示 用以上数据检验马尔萨斯 Malthus 人口指数增长模型 根据检验结果进一步讨论马尔萨斯 人口模型的改进 并利用至少两种模型来预测美国2010 年的人口数量
  • wandb安装方法及本地部署教程

    文章目录 1 wandb介绍 2 wandb安装 2 1 注册wandb账号 2 2 创建项目并获得密钥 2 3 安装wandb并登录 3 wandb本地部署 3 1 设置wandb运行模式 3 2 云端查看运行数据 4 总结 1 wand
  • 游戏开发unity编辑器扩展知识系列:扩展Hierarchy右键菜单

    代码如下 MenuItem GameObject 生成带图片的Image false 100 public void Test 效果如下 注意 MenuItem的priority参数必须小于50 MenuItem的itemName参数只支持
  • Postman和jmeter的区别(整理)

    1 创建接口用例集 没区别 Postman是Collections Jmeter是线程组 没什么区别 2 步骤的实现 有区别 Postman和jmeter都是创建http请求 a postman请求的请求URL是一个整体 jmeter分成了
  • GPU压力测试篇- TensorFlow

    简介 该文档介绍使用Tensorflow框架 测试 NVIDIA 驱动的常见python 代码 环境信息 编号 软件 软件版本 备注 01 驱动 470 57 02 02 cuda 版本 11 2 03 cudnn 版本 8 1 1 33
  • Qt控件在布局内(QFormLayout、QGridLayout等)的动态添加与删除

    项目场景 在项目开发过程中 比如报警信息的显示 如果将所有的报警信息都添加至布局内 再以控件隐藏与显示的方式进行报警 这种方法无疑是最简单的 但是如果报警种类过多 但往往需要显示的很少 在界面里面去一个个拖控件或者代码添加都太麻烦 这就需要
  • PMP常用英文术语缩写总结(文字版+表格版+图片版)

    PMP常用英文术语缩写总结 文字版 表格版 图片版 文字版 PMBOK Project Management Body of Knowledge 项目管理知识体系 PMI Project Management Institute 项目管理协
  • 数据结构--图的应用--最短路径

    最短路径 两种常见的最短路径问题 一 单源最短路径 用Dijistra迪杰斯特拉 算法 二 所有顶点间的最短路径 用Floyd 弗洛伊德 算法 Dijistra算法 1 初始化 先找出从源点v0到各终点Vk的的直达路径 V0 Vk 即通过一
  • 【element-plus】icon在菜单的使用(二)

    前言 之前觉得升级的icon不好使用是以为不能动态的设置图标 现在发现我错了 升级后的icon同样能满足之前的需求 本篇主要说明一下配置菜单时如何使用icon 一 下载依赖包 因为动态引入的icon随时都会调整 所以之前引入所有的icon最
  • 【满分】【华为OD机试真题2023B卷 JAVA&JS】VLAN资源池

    华为OD2023 B卷 机试题库全覆盖 刷题指南点这里 VLAN资源池 知识点数组字符串 时间限制 1s 空间限制 256MB 限定语言 不限 题目描述 VLAN是一种对局域网设备进行逻辑划分的技术 为了标识不同的VLAN 引入VLAN I
  • C++字符串 处理函数合集

    本博客的内容源自 数据结构 用面向对象方法与C 描述 第二版 的内容 章节4 4 在阅读原文的情况下整理得出的读书笔记 均写在代码的注释中 供大家参考 include
  • HDF5 windows编译 release版本、Debug版本

    由于最近急需的一个项目 需要hdf5库 误打误撞 编译成功 特此记录 1 下载源代码 官网下载地址 https portal hdfgroup org display support HDF5 1 12 2 files 找到如下地址 本人电