CImg 的编译错误

Compilation errors with CImg

本文关键字:错误 编译 CImg      更新时间:2023-10-16
我是第一次使用 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:informaticsProjectsimage experimentsRectangle to circle stretchersourcesmain.cpp" -o objDebugsourcesmain.o

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

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

到目前为止,我对第一个错误有一个解决方法,但对其他两个错误没有任何解决方法。

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