Compiling CImg with c++0x and MingW

会有一股神秘感。 提交于 2019-12-11 23:33:48

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!