1

This is my first time learning about Cimg. I'm trying the code from the Cimg tutorial. I get an error message, "undefined reference to SetDIBitsToDevice@48".

I am using CodeBlocks 17.12. I already linked to gdi32.lib from the Windows kit. I used the builder option -> link setting. It still tells me "undefined reference to SetDIBitsToDevice@48". After that, I changed to library "libgdi32.a" and "gdi32" and added the header file "wingdi.h" in the "Cimg.h" file. All do not work.

Here is the code from http://cimg.eu/reference/group__cimg__tutorial.html

#include "CImg.h"
using namespace cimg_library;
int main() {
    CImg<unsigned char> image("1.jpg"), visu(1920,1080,1,3,0);
    const unsigned char red[] = { 255,0,0 }, green[] = { 0,255,0 }, blue[] = { 0,0,255 };
    image.blur(2.5);
    CImgDisplay main_disp(image,"Click a point"), draw_disp(visu,"Intensity profile");
    while (!main_disp.is_closed() && !draw_disp.is_closed()) {
      main_disp.wait();
      if (main_disp.button() && main_disp.mouse_y()>=0) {
         const int y = main_disp.mouse_y();
         visu.fill(0).draw_graph(image.get_crop(0,y,0,0,image.width()-1,y,0,0),red,1,1,0,255,0);
         visu.draw_graph(image.get_crop(0,y,0,1,image.width()-1,y,0,1),green,1,1,0,255,0);
         visu.draw_graph(image.get_crop(0,y,0,2,image.width()-1,y,0,2),blue,1,1,0,255,0).display(draw_disp);
      }
    }
    return 0;
}

How can I compile it except add the #define cimg_display 0 at the head?

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
henry huang
  • 154
  • 1
  • 6
  • `lgdi32.a`??? In Code::Blocks -> Project -> Build Options -> Linker Settings -> Add >> libgdi32.a – 273K Jan 04 '19 at 05:29
  • yes, libgdi32.a, my bad. – henry huang Jan 04 '19 at 05:33
  • It must be `_SetDIBitsToDevice@48` when you target x86, the standard decoration for an stdcall function. Or plain `SetDIBitsToDevice` when you target x64. Quite doubtful that anybody could explain the wonky `|` character. Do make sure you copy/pasted the error message correctly. And do consider that there are better IDEs than Code::Blocks available on Windows. – Hans Passant Jan 04 '19 at 14:19
  • There is `SetDIBitsToDevice@48' not '_SetDIBitsToDevice@48'. I will try another IDEs, thx for suggestion. – henry huang Jan 04 '19 at 14:48
  • 1
    Surely the MSDN documentation told you "Header file: wingdi.h (include windows.h)". Follow that instruction; do not include wingdi.h directly. – Ben Voigt Jan 04 '19 at 15:21
  • I fixed it by uninstall and reinstall whole GCC and codeblocks. I guess there is something wrong on my building environment. – henry huang Jan 04 '19 at 16:23

0 Answers0