我正在尝试使用std = c ++ 0x和MingW编译以下CImg示例代码:
#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;
}
当我使用编译时:
g++ -std=c++0x HelloWorld.cpp -lgdi32
我收到以下错误:
error: '_fileno' was not declared in this scope
但是,当我在没有std = c ++ 0x的情况下进行编译时,它可以完美运行:
g++ HelloWorld.cpp -lgdi32
如何在启用c ++ 0x的情况下编译CImg?
最佳答案
我认为gnu++0x
或gnu++11
应该在GCC 4.5.x下可用,并且您应该能够使用C ++ 11编译CImg
(我刚刚在自己的MinGW安装下进行了检查,但是我使用的是4.8。您可以考虑升级吗?)。因此,您可以简单地使用:
g++ -o hello_world.exe HelloWorld.cpp -O2 -lgdi32 -std=gnu++0x
要么:
g++ -o hello_world.exe HelloWorld.cpp -O2 -lgdi32 -std=gnu++11
编辑
我刚刚检查了一下,并且
-std=gnu++11
选项自GCC 4.7起可用,但是我相信在4.5.x下使用-std=gnu++0x
应该没问题。关于c++ - 使用c++ 0x和MingW编译CImg,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22081825/