CImg库未在Dev c ++中编译

时间:2016-05-01 18:11:01

标签: c++ cimg

我已经在我的计算机上设置了dev c ++,并尝试用它编译简单的C ++ hello world代码,但是它没有编译并提供这些错误代码

C:\Users\Ignatius\Documents\testing.o   testing.cpp:(.text$_ZN12cimg_library11CImgDisplay5paintEv[__ZN12cimg_library11CImgDisplay5paintEv]+0xb2): undefined reference to `_imp__SetDIBitsToDevice@48'

C:\Users\Ignatius\Documents\collect2.exe    [Error] ld returned 1 exit status

25      C:\Users\Ignatius\Documents\Makefile.win    recipe for target 'test.exe' failed

我使用的代码是

的main.cpp

#include "CImg.h"

using namespace cimg_library;

int main()
{
    CImg<unsigned char> img(640, 400, 1, 3);
    img.fill(0);
    unsigned char purple[] = {225, 0, 225};
    img.draw_text(100, 100, "Hello world", purple);
    img.display("My first CImg code");
    system("pause");
    return 0;
}

目前这是我唯一的文件。我在线下载了CImg,并将文件夹放在正确的目录中,并将.h文件放在正确的目录中,它没有语法错误,但是编译时有人可以帮助我吗?

在Makefile.win中,汇编代码中突出显示的行是(如果有帮助)

$(BIN): $(OBJ)
$(CPP) $(LINKOBJ) -o $(BIN) $(LIBS)

1 个答案:

答案 0 :(得分:0)

CImg只是一个&#34;标题&#34; 图片,所以您不需要链接它。您需要做的就是确定CImg.h的位置,并告诉编译器-I thatplace

因此如果CImg.h位于/opt/fred,您可以

c++ program.c -I /opt/fred -o program

如果您需要链接到某个库,例如gdi32,则可能需要在结尾添加-lgdi32

c++ program.c -I /opt/fred -lgdi32 -o program