CImg 的编译错误

Compilation errors with CImg

我是第一次使用 CImg 库,我在使用仅包含 CImg.h 的简单测试程序时遇到编译错误。这是为什么?我该如何解决这个问题?

程序代码:

#include "../headers/CImg.h"
using namespace cimg_library;
int main()
{
    return 0;
}

编译错误:

In function 'FILE* cimg_library::cimg::fopen(const char*, const char*)':
5065|error: '_fileno' was not declared in this scope
In function 'int cimg_library::cimg::fseek(FILE*, INT_PTR, int)':
5093|error: '_fseeki64' was not declared in this scope
In function 'INT_PTR cimg_library::cimg::ftell(FILE*)':
5102|error: '_ftelli64' was not declared in this scope

这是在 64 位 Windows 8.1.

PC 上完成的

命令:

g++.exe -Wall -fexceptions -g -std=c++11  -c "D:\informatics\Projects\image experiments\Rectangle to circle stretcher\sources\main.cpp" -o obj\Debug\sources\main.o

我在没有 -std=c++11 部分的情况下尝试了这个,我得到了 2 个错误而不是 3 个。我没有得到 5065|error: '_fileno' was not declared in this scope。如果我用 -std=gnu++11

替换它,也会发生同样的情况

我也在我的笔记本电脑上试过了,它运行的是 windows 7 的 64 位版本,同样的情况也发生在那里。

到目前为止,我已经解决了第一个错误,但没有解决其他两个错误。

如果是 CodeBlock 16.01 stdio.h 包含行

#if __MSVCRT_VERSION__ >= 0x800
_CRTIMP int __cdecl __MINGW_NOTHROW     _fseek_nolock (FILE*, long, int);
_CRTIMP long __cdecl __MINGW_NOTHROW    _ftell_nolock (FILE*);

_CRTIMP int __cdecl __MINGW_NOTHROW     _fseeki64 (FILE*, __int64, int);
_CRTIMP __int64 __cdecl __MINGW_NOTHROW _ftelli64 (FILE*);
_CRTIMP int __cdecl __MINGW_NOTHROW     _fseeki64_nolock (FILE*, __int64, int);
_CRTIMP __int64 __cdecl __MINGW_NOTHROW _ftelli64_nolock (FILE*);
#endif

即除非 __MSVCRT_VERSION__ 至少为 0x800,否则不会声明这些函数。以下可能有效(至少它适用于 CodeBlocks 16.01)

#if defined(__MINGW32__)
#define __MSVCRT_VERSION__ 0x800
#define _WIN32_WINNT 0x0500
#endif

// if needed
// #define _fileno fileno

#include "CImg.h"

如果stdio.h不包含_fseeki64和其他人的声明,要么

  • 使用不使用_fseeki64,
  • 的CImg 1.6.9
  • 升级gcc/g++,或
  • _fseeki64 提供自己的实现(如果可以在某处找到这样的实现)。