Compiling CImg with c++0x and MingW

编制与C++ 0x CImg,MinGW

Tags: c++ c++11 cimg
标签: c++ c++11 cimg

问题 (Question)

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?

我想下面的示例代码编译CImg STD = C++ 0x和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;
}

当我编译使用:

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

我收到以下错误:

error: '_fileno' was not declared in this scope

但当我编译没有性病= C++ 0x,它完美的作品:

g++ HelloWorld.cpp -lgdi32

我怎么能用C++ 0x编译CImg启用?

最佳答案 (Best Answer)

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.

我认为gnu++0xgnu++11应可在GCC 4.5。x,你应该可以编译CImg有可能使用C + + 11(我只是检查我自己可以安装,但在我使用的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,但我认为你应该罚款-std=gnu++0x在4.5。x。

本文翻译自StackoverFlow,英语好的童鞋可直接参考原文:http://stackoverflow.com/questions/22081825