Compilation errors with CImg

安稳与你 提交于 2019-12-20 04:27:06

问题


I am using the CImg library for the first time and I get compilation errors with a simple test program that just includes CImg.h. Why is that? How can I fix this?

Program code:

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

Compilation errors:

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

This was done on a PC with a 64 bit Windows 8.1.

Command:

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

I tried this without the -std=c++11 part and I get 2 errors instead of 3. I don't get 5065|error: '_fileno' was not declared in this scope. Same happens if I replace it with -std=gnu++11

I also tried it on my laptop, which runs a 64 bit version of windows 7, and the same happens there.

So far, I have a work around for the first error, but nothing for the other two.


回答1:


In case of CodeBlock 16.01 stdio.h contains lines

#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

i.e. those functions are not declared unless __MSVCRT_VERSION__ is at least 0x800. The following might work (at least it did for CodeBlocks 16.01)

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

// if needed
// #define _fileno fileno

#include "CImg.h"

If stdio.h does not contain declaration for _fseeki64 and others, either

  • Use CImg 1.6.9 that does not use _fseeki64,
  • upgrade gcc/g++, or
  • provide an own implementation for _fseeki64 (if such one can be found somewhere).


来源:https://stackoverflow.com/questions/38402058/compilation-errors-with-cimg

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!