Compilation 在windows上使用minGW的HDF5

Compilation 在windows上使用minGW的HDF5,compilation,makefile,linker,fortran,gfortran,Compilation,Makefile,Linker,Fortran,Gfortran,我正试图用Fortran程序编译并链接到HDF5,但我遇到了一个运行时错误。我严格遵循了这个问题的答案中描述的程序 我在环境变量中设置了路径,而不是在VisualStudio中设置它们。我将所有生成的.mod和.lib文件移动到项目文件夹中的mod和lib文件夹中 在命令提示符下,我的编译器配置如下 gfortran --version GNU Fortran (x86_64-posix-seh-rev0, Built by MinGW-W64 project) 4.9.2 gmake -

我正试图用Fortran程序编译并链接到HDF5,但我遇到了一个运行时错误。我严格遵循了这个问题的答案中描述的程序

我在环境变量中设置了路径,而不是在VisualStudio中设置它们。我将所有生成的.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
 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 $@ $<
我的makefile看起来像

 gfortran --version
 GNU Fortran (x86_64-posix-seh-rev0, Built by MinGW-W64 project) 4.9.2
 gmake --version
 GNU Make 3.81
 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 $@ $<
当我尝试运行可执行文件时,会弹出一个窗口,显示应用程序无法正确启动0xc000007b。单击“确定”关闭应用程序

此链接

表明这是由于32位到64位不兼容造成的。我使用的是64位机器,我确实下载了32位版本的CMake,但这只是因为似乎没有适用于64位机器的版本。另外,这个链接

表明这不重要。所以我的问题是,我哪里做错了?到目前为止,我所展示的有没有明显的错误

更新:

我发现运行时错误是由于没有指定路径造成的,在本例中为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
是最重要的一个,因为这可能会引发以后的问题。根据这条线索

如果我没有弄错的话,建议使用与构建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
希望这能帮助别人