0

I am trying to set up Eclipse IDE 2020-06 on MacOS Catalina (10.15.6) such that it works with CImg. I am running the standard program as provided on the CImg:

using namespace cimg_library;

int main() {
  CImg<unsigned char> image("lena.jpg"), visu(500,400,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;
}

This works perfectly fine when compiling and running it from the terminal using:

    >> g++ -o load_image.o -L /opt/X11/lib -I /opt/X11/include load_image.cpp -lX11 -lpthread
    >> ./load_image.o

When I try to do this from Eclipse the compilation works fine, but when trying to run the code I get the error:

[CImg] *** CImgIOException *** [instance(0,0,0,0,0x0,non-shared)] CImg<unsigned char>::load(): Failed to recognize format of file 'lena.jpg'.
libc++abi.dylib: terminating with uncaught exception of type cimg_library::CImgIOException: [instance(0,0,0,0,0x0,non-shared)] CImg<unsigned char>::load(): Failed to recognize format of file 'lena.jpg'.

The includes and libraries set up in eclipse are as below: 1

2

Does anybody know what is wrong with my settings in Eclipse?

Edit: As suggested, the used debugger settings are as shown below: 3

Update When running the terminal-compiled program with gdb I get no problems. I can not test if the eclipse-compiled program runs in terminal due to those files being locked somehow.

Bjorn
  • 303
  • 2
  • 4
  • 10
  • I believe imagemagick won't have to do anything with the problems you're facing, removed the tag. Also the include and library settings are irrelevant, as long eclipse managed to build your program without any failures. I'd suspect it's more a problem where the final program is executed by eclipse. Would be more interesting to se a screenshot of your debugger settings in the eclipse IDE. – πάντα ῥεῖ Sep 11 '20 at 13:16
  • Add a statement to print the current working directory (see the `getcwd() ` function). It will be different for both means of invocation. Either change the working directory in your run configuration or use absolute paths. – Botje Sep 11 '20 at 13:28
  • If you want `CImg` to read/write JPEGs itself, you need `#define cimg_use_jpeg` in your Project Settings and you need to have `libjpeg` installed, probably with `brew install libjpeg` and you need to link to it. https://stackoverflow.com/a/47375364/2836621 – Mark Setchell Sep 13 '20 at 12:23
  • @πάνταῥεῖ I added a screenshot of the debugger settings. – Bjorn Sep 14 '20 at 06:37
  • @Botje The path for both invocations is the same – Bjorn Sep 14 '20 at 06:37
  • @MarkSetchell Why would this be necessary if it works without it when running from terminal? – Bjorn Sep 14 '20 at 06:37

0 Answers0