c++ - 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 看起来相当容易使用,但是如果您使用其他库来编辑照片,请告诉我。
提前致谢!
解决方案
我认为您需要在 Windows 上链接到 GDI32。就像是:
g++ tutorial.cpp -lgdi32 -o tutorial.exe
推荐阅读
- c# - 在将 MSAL 身份验证提供程序与 Micrsoft Graph SDK 和 Azure 函数一起使用时,每当添加新线程时都会获取新令牌
- reactjs - 输入时光标向左跳直到 2 个字符后
- javascript - 如何在 javascript/nodejs 中将数据附加到具有特定索引的 JSON
- augmented-reality - 有人已经尝试过使用当前的 Macbook Pro 为 Hololens 2 进行开发吗?
- excel - 打开现有 Word Doc 时,有没有办法绕过“正在使用的文件”对话框?
- spring-boot - @ConfigurationProperites 升级到 Spring Cloud Hoxton.SR7 后未绑定到属性源
- ios - 应用程序在 iOS 14 测试版中卡在多个位置
- python - 根据数据框中的日期时间创建订单列
- javascript - JavaScript Web Worker 消息
- regex - bash grep regex 如何不 grep 时间戳