首页 > 解决方案 > CImg 库编译时返回未定义的引用 `__imp_SetDIBitsToDevice'

问题描述

我在安装了 MinGW 编译器的 Windows 10 上使用 VSCode。我尝试使用 CImg 库来编辑图像(http://cimg.eu/),当我尝试从教程(http://cimg.eu/reference/group__cimg__tutorial.html)编译代码时,我明白了错误:

C:\Users\Martini\AppData\Local\Temp\ccBswQ5w.o:tutorial.cpp:(.text$_ZN12cimg_library11CImgDisplay5paintEv[_ZN12cimg_library11CImgDisplay5paintEv]+0xba): undefined reference to `__imp_SetDIBitsToDevice'
collect2.exe: error: ld returned 1 exit status

我有 CImg.h 文件位于 tutorial.cpp 文件夹中。这是我用来编译的命令:

g++ tutorial.cpp -o tutorial.exe

这是我第一次使用 C++ 中的库,CImg 看起来相当容易使用,但是如果您使用其他库来编辑照片,请告诉我。

提前致谢!

标签: c++cimg

解决方案


我认为您需要在 Windows 上链接到 GDI32。就像是:

g++ tutorial.cpp -lgdi32 -o tutorial.exe

推荐阅读