0

I am trying to compile the following CImg sample code with std=c++0x and MingW:

#include "CImg.h"

using namespace cimg_library;

int main() {
    CImg<unsigned char> img(640,400,1,3); 
    img.fill(0); 
    unsigned char purple[] = { 255,0,255 }; 
    img.draw_text(100,100,"Hello World",purple);
    img.display("My first CImg code");
    return 0;
}

When I compile using:

g++ -std=c++0x HelloWorld.cpp -lgdi32

I get the following error:

error: '_fileno' was not declared in this scope

But when I compile without std=c++0x, it works perfectly:

g++ HelloWorld.cpp -lgdi32

How can I compile CImg with c++0x enabled?

Jaime Ivan Cervantes
  • 3,579
  • 1
  • 40
  • 38

1 Answers1

2

I think that gnu++0x or gnu++11 should be available under under GCC 4.5.x and with that you should be able to compile CImg with a possibility to use C++11 (I just checked under my own MinGW installation, however I'm using 4.8. Could you consider upgrading?). So you could simply use:

g++ -o hello_world.exe HelloWorld.cpp -O2 -lgdi32 -std=gnu++0x

Or:

g++ -o hello_world.exe HelloWorld.cpp -O2 -lgdi32 -std=gnu++11

EDIT

I just checked and -std=gnu++11 option is available since GCC 4.7, but I believe you should be fine with -std=gnu++0x under 4.5.x.

Peter Nimroot
  • 545
  • 5
  • 14
  • Thanks Peter. I tested std=gnu++0x and it worked. But even after I google it, I still fail to understand the difference between gnu++0x and c++0x. Could you explain the difference? – Jaime Ivan Cervantes Feb 28 '14 at 15:10
  • 1
    @JaimeIvanCervantes Sure. by quoting the [GCC](http://gcc.gnu.org/projects/cxx0x.html): "To enable C++0x support, add the command-line parameter -std=c++0x to your g++ command line. Or, `to enable GNU extensions in addition to C++0x extensions`, add -std=gnu++0x to your g++ command line.". So, basically it means that it's C++11 with some GNU extensions. More information can be found in here: http://stackoverflow.com/questions/10613126/what-are-the-differences-between-std-c11-and-std-gnu11 – Peter Nimroot Feb 28 '14 at 15:19