问题
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?
回答1:
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.
来源:https://stackoverflow.com/questions/22081825/compiling-cimg-with-c0x-and-mingw