CImg的编译错误

时间:2016-07-15 17:31:44

标签: c++ compilation compiler-errors 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

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

我也在我的笔记本电脑上试过它,它运行64位版本的Windows 7,并且在那里也是如此。

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

1 个答案:

答案 0 :(得分:2)

如果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提供了自己的实现(如果可以在某处找到这样的实现)。