HDF5 C++ Qt 冲突声明



情况:我需要读取一个.hdf5文件,并在使用Qt创建的界面中以图形方式显示数据。

做了什么:我创建了一个新项目,只是使用 qt 向导将hdf5.lib作为外部库添加到hdf5_test.pro中,并在mainwindow.h#include <hdf5.h>

问题:尝试运行代码时,出现此错误:conflicting declaration 'typedef long long ssize_t'


用:

  • C++
  • Qt 5.10.1
  • MinGW 5.3.0 32位C++
  • HDF5 1.10.2

我的代码:

#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <hdf5.h>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H

QT       += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = hdf5_test
TEMPLATE = app
# The following define makes your compiler emit warnings if you use
# any feature of Qt which has been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
SOURCES += 
main.cpp 
mainwindow.cpp
HEADERS += 
mainwindow.h
FORMS += 
mainwindow.ui
win32:CONFIG(release, debug|release): LIBS += -L'C:/Program Files/HDF_Group/HDF5/1.10.2/lib/' -lhdf5
else:win32:CONFIG(debug, debug|release): LIBS += -L'C:/Program Files/HDF_Group/HDF5/1.10.2/lib/' -lhdf5d
else:unix: LIBS += -L'C:/Program Files/HDF_Group/HDF5/1.10.2/lib/' -lhdf5
INCLUDEPATH += 'C:/Program Files/HDF_Group/HDF5/1.10.2/include'
DEPENDPATH += 'C:/Program Files/HDF_Group/HDF5/1.10.2/include'


这可能是一个类似的问题,但没有答案。

这是一个黑客,但hdf5.h检查H5_SIZEOF_SSIZE_T是否等于零。所以使用

#define H5_SIZEOF_SSIZE_T H5_SIZEOF_LONG_LONG

在包含HDF5.h之前,可以通过不重新定义类型来提供帮助。

最新更新