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

HDF5 windows编译 release版本、Debug版本相关推荐

  1. android发布release版本,Android同时安装Release和Debug版本的方法

    一般项目做到后期,在测试的时候,需要在测试版本和正式版本之间进行频繁的切换,怎么办呢?土豪的话可以考虑使用两台机器,同时测试,然而为了方便测试,节约成本,最好的办法当然是在同一台机器上安装不同的版本. ...

  2. gcc中的debug版本和release版本

    结论:Gcc中并没有Release和debug版本之分,只有编译选项的组合 大学时候使用VS开发,VS编译的程序是可以选debug或者release的,搞得我一直误以为使用gcc编译,也有这种区分. ...

  3. java编译release版本断言_关于Debug和Release之本质区别

    经常在 CSDN 上看见有人问 Debug 运行正常但 Release 失败的问题.以往的讨论往往是 经验性的,并没有指出会这样的真正原因是什么,要想找出真正的原因通常要凭运气.最 近我看了一些这方面 ...

  4. linux release 版本的区别,编译debug版本和编译release版本的区别

    大项目的版本编译会区别debug和release,那debug和release会有什么区别呢? 通过对比这两者的编译选项可以找到答案. 1.对比编译过程 debug: -DOS_LINUX  -DDE ...

  5. [Happy Coding] 加速Windows GUI debug版本的编译

    加速Windows GUI debug版本的编译 1. 问题描述 我们重构我们的GUI程序时,增加了很多小的工程库,VC2008编译GUI最顶层DLL库libpkgA的速度让人几乎无法忍受. 以下是从 ...

  6. VC++调试程序、快捷键以及Debug版本与Release版本

    1.如何在Release状态下进行调试 Project->Setting=>ProjectSetting对话框,选择Release状态.C/C++标签中的Category选General, ...

  7. release版本和debug版本

    程序一般分为Debug版本和Release版本,Debug版本用于内部调试,Release版本发行给用户使用 Release和Debug有什么不同 Release版称为发行版,Debug版称为调试版. ...

  8. Debug版本下能运行而Release下不能运行的问题总结

    引言      如果在您的开发过程中遇到了常见的错误,或许您的Release版本不能正常运行而Debug版本运行无误,那么我推荐您阅读本文:因为并非如您想象的那样,Release版本可以保证您的应用程 ...

  9. windows编译openssl xp版本

    Windows编译Openssl(1.1.1) xp版 1. Openssl源码下载 openssl下载 2 . 安装Perl ActivePerl下载 下载完再终端输入perl -v验证是否安装成功 ...

最新文章

  1. 苹果手机怎么设置时间24小时制_外媒实测苹果iPhone 12续航:5G网络下表现不佳...
  2. 从《芈月传》看热门IP在互联网视频行业的“前世今生”
  3. 滑动listview隐藏和显示顶部布局
  4. 《Java8实战》笔记(05):使用流
  5. 学习笔记之 prim算法和kruskal算法
  6. MATLAB 添加自有的工具包
  7. cv2图像显示的像素值0-10-255和显示
  8. 水晶报表攻克系列3-如何在程序中自定义纸张
  9. oracle sum里面去重,Oracle中碰到的函数和关键字收集
  10. 素士科技IPO折戟,困于营销和小米
  11. python做3d相册_简单3D翻页相册制作教程(示例代码)
  12. Android内存泄漏检测工具大全
  13. miuiv13-redmi-note11TPro-root
  14. 微信公众号 关注推送消息报错 45047
  15. 华硕笔记本(GTX 1060显卡)安装Ubuntu16.04+Nvidia显卡驱动+Cuda8.0+cudnn6.0+ROS+Opencv3.2+Caffe+Tensorflow
  16. HTML中<a></a>标签的四大功能 必看!必看!!必看!!!
  17. 【AI视野·今日NLP 自然语言处理论文速览 第三期】Tue, 8 Jun 2021
  18. sqlloader导出数据指定分隔符_来一份数据库全家桶~
  19. 量化交易必看电影之《蜂鸟计划》
  20. Wine零知识学习1 —— 介绍

热门文章

  1. 张小龙:做 PC 版微信是一种破坏
  2. 如何全链路进行前端性能优化
  3. GAN“家族”又添新成员——EditGAN,不但能自己修图,还修得比你我都好
  4. mysql的default_sql语句中default是什么意思?
  5. 语音唤醒技术的原理是什么?
  6. 小红书笔记怎么写提高转化率
  7. 家用计算机都是专用计算机吗,什么是因特网概念和互联网一样吗(因特网发展历程)...
  8. 北京理工大学本科毕业论文答辩和论文选题PPT模板
  9. 【Ice】【01】linux 安装ice
  10. 【像素与浏览器视口的细节】及移动web设置“width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no“原因