c - 使用 MinGW 和 CMake 编译 HDF5 时出错

标签 c windows mingw hdf5

我正在尝试使用 MinGW 的 gcc 4.8.1 和 CMake 编译 HDF5。我按照 Windows 的 INSTALL_CMake 文档中的说明阅读了我在 Google 上找到的所有内容,但我仍然收到以下错误:

In file included from c:\mingw32-xy\include\fcntl.h:37:0,
                 from C:\Users\jicervan.NDC\Downloads\hdf5-1.8.13\hdf5-1.8.13\src\H5private.h:53,
                 from C:\Users\jicervan.NDC\Downloads\hdf5-1.8.13\hdf5-1.8.13\src\H5detect.c:57:
c:\mingw32-xy\include\io.h:301:1: error: unknown type name 'off64_t'
 __CRT_INLINE off64_t lseek64 (int, off64_t, int);
 ^
c:\mingw32-xy\include\io.h:301:36: error: unknown type name 'off64_t'
 __CRT_INLINE off64_t lseek64 (int, off64_t, int);
                                    ^
c:\mingw32-xy\include\io.h:302:1: error: unknown type name 'off64_t'
 __CRT_INLINE off64_t lseek64 (int fd, off64_t offset, int whence) {
 ^
c:\mingw32-xy\include\io.h:302:39: error: unknown type name 'off64_t'
 __CRT_INLINE off64_t lseek64 (int fd, off64_t offset, int whence) {
                                       ^
In file included from C:\Users\jicervan.NDC\Downloads\hdf5-1.8.13\hdf5-1.8.13\src\H5private.h:70:0,
                 from C:\Users\jicervan.NDC\Downloads\hdf5-1.8.13\hdf5-1.8.13\src\H5detect.c:57:
c:\mingw32-xy\include\unistd.h:65:20: error: unknown type name 'off_t'
 int ftruncate(int, off_t);

错误和警告不断出现,还有一长串警告和未定义。有人对如何解决这个问题有什么建议吗?是否有任何其他替代方案,例如将 Visual Studio 二进制文件与 MinGW 一起使用?

最佳答案

我终于让它工作了。我的第一次尝试是使用 configuremake根据 /release_docs/INSTALL_MinGW.txt 中的文档文件,但没有用。我最终使用了 CMake。出于文档目的,这是我遵循的过程:

OPERATING SYSTEM: Windows 8.1 pro

COMPILER: CMake + MinGW gcc version 4.8.1

HDF5 VERSION: 1.8.13

步骤:

  1. 解压缩 hdf5-1.8.13.zip文件。

  2. 下载 CMake,并运行 GUI。

  3. 将源文件夹设置为<hdf5-location>/hdf5-1.8.13和构建文件夹到您要放置 Makefile 的文件夹。

CMake GUI

  1. 点击 Configure , 将出现一个弹出窗口。选择MinGW Makefiles选项作为项目的生成器,然后选择 Use default native compilers option .

Project Generator

  1. 列表填满选项后,保持选中默认复选框,同时选择BUILD_SHARED_LIBRARIES。 .现在乐趣开始了;编译。

Options

  1. 找到文件 H5pubconfig.h在 HDF5 构建文件夹中添加文件并附加以下行:

    // Define Windows 32
    #ifndef H5_HAVE_WIN32_API
    #ifdef WIN32 /* defined for all windows systems */
    #define H5_HAVE_WIN32_API 1
    #endif
    #endif
    
    // Define MinGW
    #ifndef H5_HAVE_MINGW
    #ifdef __MINGW32__ /*defined for all MinGW compilers */
    #define H5_HAVE_MINGW 1
    #endif
    #endif
    
    // Redefine _In_ and _Out_ to empty values
    #define _In_
    #define _Out_
    
    // Redefine off_t and off64_t to match io.h and unistd.h
    #define off_t _off_t
    #define off64_t _off64_t
    
  2. 在文件上 io.h位于<MyFolder>/MinGW32/include/更改 off64_t 的每个实例至 _off64_t .

  3. 在文件上 unistd.h位于<MyFolder>/MinGW32/include/更改 off_t 的每个实例至 _off_t .

  4. 在 MinGW/MSYS 命令提示符下,将目录更改为 HDF5 Makefile 的位置(在第 3 步中设置)。

  5. 键入命令 Make并验证它是否已正确编译。

  6. 不要忘记包含标志 -I/<your-HDF5-build-folder>/include/ , -L/<your-HDF5-build-folder>/bin/ , 和 -lhdf5当你编译。快乐编码。

关于c - 使用 MinGW 和 CMake 编译 HDF5 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25730692/

相关文章:

c - 使函数指针成为c中结构的成员

java - 替换 2D char* 数组中的字符串值 c/java jni

c++ - MFC对话框列表控件的工具提示

python - 可以在没有 Visual Studio 的情况下使用 MinGw 编译 python.exe

c++ - SDL - 像控制台一样打印文本?

c - 用户输入另一个数据时的数组放置

c - 简单的 C 错误 - #include?

python - 如何让你的主窗口在 Tkinter 成功登录后出现(PYTHON 3.6

c# - 自制服务器场和远程调试

c - 带有 MinGW 的 Eclipse 没有正确链接