CImg库未在Dev c++中编译
CImg library not compiling in Dev c++
我已经在我的计算机上设置了dev c++,并试图用它编译简单的c++hello world代码,但它没有编译,并给出了这些错误代码
C:UsersIgnatiusDocumentstesting.o testing.cpp:(.text$_ZN12cimg_library11CImgDisplay5paintEv[__ZN12cimg_library11CImgDisplay5paintEv]+0xb2): undefined reference to `_imp__SetDIBitsToDevice@48'
C:UsersIgnatiusDocumentscollect2.exe [Error] ld returned 1 exit status
25 C:UsersIgnatiusDocumentsMakefile.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)
CImg
是一个"header-only"库,所以您不需要链接它。您所需要做的就是确定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