如何将hdf5添加到Qt项目

如何将hdf5添加到Qt项目

本文介绍了如何将hdf5添加到Qt项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

情况:

我需要在我的qt项目中添加一个库(以我的情况为HDF5).

I need to add a library (HDF5 in my case) to my qt project.

我知道如何为自己的目的编写足够的c ++代码,但是我对.pro文件一无所知.当我尝试使用Google搜索我的问题或添加库的一般指南时,我发现了很多答案,但是却一无所知,因为它们需要的知识比我多.他们说诸如到处编译",将其添加到系统中",在目录xyz中使用qmake"之类的东西.有人可以回答这个问题吗,这样一个只懂一点c ++和绿色编译的人就可以了. qt的运行按钮明白吗?会很棒:-)

I know how to code c++ enough for my purposes, but i have no clue about the .pro file. When i try to google my problem or general guides for adding libraries i find lots of answers but understand none of them, because they require more knowledge then i have. They say stuff like "compile it here and there", "add this and that to your system", "use qmake in directory xyz". Can someone please answer the question so that one who only knows a bit of c++ and the green compile & run button of qt understands it? Would be great :-)

我累了:

我知道qt中有一个Wizarb,可以将库添加到项目中.我用它来添加所需的库.我将它们添加为外部库".我尝试以动态或静态方式进行尝试,也尝试仅添加hdf5.libhdf5_cpp.lib.

I know that there is a wizarb in qt that can add librarys to projects. I used it to add the libraries needed. I added them as "external librarys".I tried as dynamic or static, i tried adding only the hdf5.lib or the hdf5_cpp.lib too.

问题:

当我如上所述进行操作并尝试使用添加的库中的函数时,我总是会收到类似以下错误:undefined reference to H5::Function_Name_xyz.

When I do it as I described above and try to use a function from the added library i always get errors like: undefined reference to H5::Function_Name_xyz.

我的.pro外观(由qt add-library-wizard生成):

My .pro looks like (generated by the qt add-library-wizard):

TEMPLATE = app
CONFIG += console c++11
CONFIG -= app_bundle
CONFIG -= qt

SOURCES += \
        main.cpp


#Add external static library "hdf5.lib":
unix|win32: 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'

win32:!win32-g++: PRE_TARGETDEPS += 'C:/Program Files/HDF_Grou/HDF5/1.10.2/lib/hdf5.lib'


#Add external static library "hdf5_cpp.lib"
unix|win32: LIBS += -L'C:/Program Files/HDF_Group/HDF5/1.10.2/lib/' -lhdf5_cpp

INCLUDEPATH += 'C:/Program Files/HDF_Group/HDF5/1.10.2/include'
DEPENDPATH += 'C:/Program Files/HDF_Group/HDF5/1.10.2/include'

win32:!win32-g++: PRE_TARGETDEPS += 'C:/Program Files/HDF_Group/HDF5/1.10.2/lib/hdf5_cpp.lib'

使用:

  • C ++
  • Qt 5.10.1
  • MinGW 32位
  • HDF5 1.10.2
  • Windows 7

推荐答案

我不久前也遇到了同样的问题.我做了以下操作来纠正链接错误.

I had this same issue awhile back. I did the following to correct the linking error.

  1. 在将新库添加到.pro文件之后,请确保您运行qmake(构建->运行qmake).
  2. 由于您将Windows与预构建的HDF库一起使用,因此应使用MSVC2015 32位Build& Run工具包.预先构建的库使用Microsoft Visual C ++编译器,因此要使用HDF库,您将需要使用该编译器.
  3. 根据HDF文档,您需要首先列出外部库.以下代码段显示了我使用动态库的设置.
  4. 如果您使用动态库,请确保将DEFINES += H5_BUILT_AS_DYNAMIC_LIB添加到您的.pro文件中.
  1. Make sure you run qmake (Build-> Run qmake) after adding a new library to the .pro file.
  2. Since you are using windows with the pre-built HDF library, you should use the MSVC2015 32 bit Build&Run kit. The pre-built libraries used Microsoft Visual C++ compiler, so to use the HDF libraries you will need to use that compiler.
  3. Per the HDF documentation, you need to list the external libraries first. The following snippit shows my setup using dynamic libraries.
  4. If your using dynamic libraries be sure to add DEFINES += H5_BUILT_AS_DYNAMIC_LIB to your .pro file.
win32: LIBS += -L$$PWD/'../../../../../Program Files/HDF_Group/HDF5/1.10.4/lib/' -lszip -lzlib -lhdf5 -lhdf5_cpp

INCLUDEPATH += $$PWD/'../../../../../Program Files/HDF_Group/HDF5/1.10.4/include'
DEPENDPATH += $$PWD/'../../../../../Program Files/HDF_Group/HDF5/1.10.4/include'

这篇关于如何将hdf5添加到Qt项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-25 20:30