c++cimg

CImg library when compiling return undefined reference to `__imp_SetDIBitsToDevice'


I'm using VSCode on Windows 10 with MinGW compiler installed. I've tried using CImg library to edit images (http://cimg.eu/), and when I'm trying to compile code from tutorial (http://cimg.eu/reference/group__cimg__tutorial.html) I get this error:

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

I have CImg.h file located in folder with tutorial.cpp. Here's command I'm using to compile:

g++ tutorial.cpp -o tutorial.exe

It's my first time working with libraries in C++, and CImg looks fairly easy to use, but if you have used other libraries to edit photos, let me know.

Thanks in advance!


Solution

  • You need to link to GDI32 on Windows I think. Something like:

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