使用c ++ 0x和MingW编译CImg [英] Compiling CImg with c++0x and MingW
问题描述
我正在尝试使用std = c ++ 0x和MingW编译以下CImg示例代码:
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
我收到以下错误:
error: '_fileno' was not declared in this scope
但是当我不使用std = c ++ 0x进行编译时,它可以完美运行:
But when I compile without std=c++0x, it works perfectly:
g++ HelloWorld.cpp -lgdi32
如何在启用c ++ 0x的情况下编译CImg?
How can I compile CImg with c++0x enabled?
推荐答案
我认为gnu++0x
或gnu++11
应该在GCC 4.5.x下可用,并且您应该能够使用使用C ++ 11的可能性(我刚刚在自己的MinGW安装下进行了检查,但是我使用的是4.8.您可以考虑升级吗?).所以您可以简单地使用:
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
或者:
g++ -o hello_world.exe HelloWorld.cpp -O2 -lgdi32 -std=gnu++11
编辑
我刚刚检查过,从GCC 4.7开始,-std=gnu++11
选项可用,但是我相信在4.5.x下使用-std=gnu++0x
应该没问题.
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.
这篇关于使用c ++ 0x和MingW编译CImg的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!