我正在尝试使用 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 一起使用?
最佳答案
我终于让它工作了。我的第一次尝试是使用 configure
和 make
根据 /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
步骤:
解压缩
hdf5-1.8.13.zip
文件。下载 CMake,并运行 GUI。
将源文件夹设置为
<hdf5-location>/hdf5-1.8.13
和构建文件夹到您要放置 Makefile 的文件夹。
- 点击
Configure
, 将出现一个弹出窗口。选择MinGW Makefiles
选项作为项目的生成器,然后选择Use default native compilers option
.
- 列表填满选项后,保持选中默认复选框,同时选择
BUILD_SHARED_LIBRARIES
。 .现在乐趣开始了;编译。
找到文件
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
在文件上
io.h
位于<MyFolder>/MinGW32/include/
更改off64_t
的每个实例至_off64_t
.在文件上
unistd.h
位于<MyFolder>/MinGW32/include/
更改off_t
的每个实例至_off_t
.在 MinGW/MSYS 命令提示符下,将目录更改为 HDF5 Makefile 的位置(在第 3 步中设置)。
键入命令
Make
并验证它是否已正确编译。不要忘记包含标志
-I/<your-HDF5-build-folder>/include/
,-L/<your-HDF5-build-folder>/bin/
, 和-lhdf5
当你编译。快乐编码。
关于c - 使用 MinGW 和 CMake 编译 HDF5 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25730692/