在 windows 上使用来自 minGW 的 HDF5

Use HDF5 from minGW on windows

我正在尝试使用 Fortran 程序编译并 link 为 HDF5,但出现 运行 时错误。我已密切关注此问题的答案中描述的程序

Use HDF5 from intel fortran on windows

我在环境变量中设置了 PATH,而不是在 visual studio 中设置它们。我将所有生成的 .mod 和 .lib 文件移动到项目文件夹中的 mod 和 lib 文件夹。

在命令提示符下,我的编译器配置类似于

 gfortran --version
 GNU Fortran (x86_64-posix-seh-rev0, Built by MinGW-W64 project) 4.9.2
 gmake --version
 GNU Make 3.81

我的 makefile 看起来像

 ifdef SystemRoot
     PATHSEP2 = \
 else
     PATHSEP2 = /
 endif
 PS = $(strip $(PATHSEP2))

 OBJ_DIR = obj
 MOD_DIR = mod
 LIB_DIR = lib

 FC      = gfortran
 FCFLAGS = -I$(MOD_DIR) -g -Wall
 FLFLAGS = -I$(MOD_DIR) -L$(LIB_DIR) -l$(LIB_DIR)hdf5_fortran

 SRCS_F = testHDF5.f90

 TARGET = testHDF5

 all: $(TARGET)

 testHDF5: testHDF5.f90 
  $(FC) -o $@ testHDF5.f90 $(FLFLAGS)

 $(OBJ_DIR)$(PS)%.o: %.f90
  $(FC) $(FCFLAGS) -c -o $@ $<

我已将 hdf5_fortran.lib 更改为 libhdf5_fortran.lib 因为我在此处阅读的内容

http://www.mingw.org/wiki/specify_the_libraries_for_the_linker_to_use

当我 运行 gmake 时,我得到

 gfortran -o testHDF5 testHDF5.f90 -Imod -Llib -llibhdf5_fortran

当我尝试 运行 可执行文件时,会弹出一个 window,上面写着 "The application was unable to start correctly (0xc000007b). Click OK to close the application."

这个link

http://www.solveinweb.com/solved-the-application-was-unable-to-start-correctly-0xc000007b-click-ok-to-close-the-application/

提示是32位与64位不兼容所致。我使用的是 64 位机器,我确实下载了 32 位版本的 CMake,但这只是因为似乎没有适用于 64 位机器的可用版本。另外,这个link

http://www.cmake.org/pipermail/cmake/2010-September/039375.html

表明这应该无关紧要。所以我的问题是,我哪里出错了?到目前为止我展示的内容是否有任何明显的错误?

更新:

我发现 运行 时间错误是由于未指定路径造成的,在本例中为 HDF5_DIR。在USING_HDF5_CMAKE文档里说要指定环境变量

 HDF5_DIR=C:/Program Files/HDF_Group/HDF5/1.8.x/cmake/hdf5

修复了应用程序一开始就崩溃的问题。但是现在,我得到了错误

 HDF5-DIAG: Error detected in HDF5 (1.8.14) thread 0:
   #000: C:\Users\Charlie\Downloads\CMake\hdf5-1.8.14\src\H5D.c line 167 in H5Dcr
 eate2(): not a datatype ID
     major: Invalid arguments to routine
     minor: Inappropriate type
 HDF5-DIAG: Error detected in HDF5 (1.8.14) thread 0:
   #000: C:\Users\Charlie\Downloads\CMake\hdf5-1.8.14\src\H5D.c line 415 in H5Dcl
 ose(): not a dataset
     major: Invalid arguments to routine
     minor: Inappropriate type

我想是第一个错误

 HDF5-DIAG: Error detected in HDF5 (1.8.14) thread 0:
   #000: C:\Users\Charlie\Downloads\CMake\hdf5-1.8.14\src\H5D.c line 167 in H5Dcr
 eate2(): not a datatype ID
     major: Invalid arguments to routine
     minor: Inappropriate type

是最重要的一个,因为它可能会触发后面的一个。根据这个线程

http://hdf-forum.184993.n3.nabble.com/HDF5-Fortran-Fail-to-execute-of-a-basic-F90-program-td4026778.html

建议使用与构建 Fortran 源代码相同的编译器来构建库(如果我没记错的话)。在使用 CMake 构建期间,我指定使用 MinGW,我相信在两个构建期间都使用了它,对吗?

再次感谢您对此的任何帮助。

我就此问题联系了 hdf5 支持

 Platform/OS:
 Windows 7

 Product/Version:
 HDF5, Latest download

 Description:
 Hi, I'm having trouble getting HDF5 working on my windows machine with fortran. Below is an outline of what I've done, and after I show the error I get. 

 1.1) Download and install CMake, Windows (Win 32 Installer) from http://www.cmake.org/download/ 

 1.2) I did not add CMake to the system PATH, because it was too long. 

 1.3) I manually added "C:/Program Files (x86)/CMake/bin" to the PATH (for user)
 in computer->properties->advanced system settings->environment variables 2.1) Download and install HDF5 

 2.2) I manually added "C:/Program Files/HDF Group/HDF5/1.8.14/cmake/hdf5" to the PATH (for user) in computer->properties->advanced system settings->environment variables 

 3.1) I created a new, empty, directory (/Project/) and copied HDF5Examples-0.1.1-Source.zip and HDF518 Examples.CMAKE to it. 3.1) Downloaded hdf5-CMakeWindows.zip from http://www.hdfgroup.org/HDF5/release/cmakebuild.html and unzipped
 file to find a folder named CMake. 

 3.2) Opened CMake GUI, set Source Code Dir = CMake/hdf5-1.8.14 folder 

 3.3) Set Where to build binaries Dir = /Project/ (project folder containing HDF5Examples-0.1.1-Source.zip and HDF518 Examples.CMAKE) 

 4.1) In the CMake GUI, I pressed Configure, (selected MinGW and default from the 1st and 2nd drop down respectively), Configure. Checked BUILD_SHARED_LIBS and HDF5_BUILD_FORTRAN. Configure, configure, generate. 

 4.2) I navigated to the bin directory of the CMake folder and copied the library files, .dll files, and .mod files to an empty test folder (/test_HDF5/), where I separated them into lib/mod folders. 

 4.3) I created a makefile which, if done correctly, linked the .lib files. 

 4.4) I compiled the files and linked the libraries and there seemed to be no errors, nor warnings. When running the testHDF5.exe I received the following error: The application was unable to start correctly (0xc000007b). Click OK to close the application. I believe this is a configuration issue, and I'm not sure how to resolve it. 

 I'm very new with linking libraries and I'm just trying to use HDF5 as a data exporting tool with my existing fortran code. Any help is greatly appreciated. 

 Sincerely, Charlie Kawczynski

他们的回复是,截至 2015 年 4 月 14 日,MinGW 不受支持:

 Hi Charlie,

 We do not support MinGW at this time. The developer had tried
 building with Fortran and was not able to get it to work.

 We do have a user forum where you can post questions. However, others
 have posted issues about MinGW and Fortran that have not been resolved. :(

 For information on the HDF Forum, see:
    http://www.hdfgroup.org/services/community_support.html

 -Barbara

希望这对其他人有帮助。