我第一次使用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位Windows8.1的个人电脑上完成的。
命令:
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部分的情况下,我尝试了这一点,我得到了两个错误,而不是3个。我没有得到5065|error: '_fileno' was not declared in this scope。如果用-std=gnu++11替换它,也会发生同样的情况。
我还在我的笔记本电脑上试用了它,它运行的是windows 7的64位版本,在那里也是如此。
到目前为止,我已经做了第一个错误的工作,但对其他两个没有。
发布于 2016-07-18 22:39:06
如果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,_fseeki64提供自己的实现(如果可以在某个地方找到这种实现)。https://stackoverflow.com/questions/38402058
复制相似问题