1

I'm trying to run a simple program that uses CImg with Eclipse:

#include <iostream>
#include<X11/Xlib.h>
#include "CImg.h"

using namespace cimg_library;

int main()
{
    // read a jpg image
    CImg<float> imgin("frog.jpg");
    CImg<float> black_white;
    // do some computation on the pixels (R,G,B values)
    for(int i=0; i<100; i++)
        for(int j=0; j<10; j++)
            imgin(i,i+j,0) = imgin(i,i+j,1) = imgin(i, i+j, 2) = 0;
    // write image back
    imgin.save("frog2.jpg");
    black_white = imgin.get_RGBtoYCbCr().get_channel(0);
    black_white.save("frog3.jpg");
    return(0);
}

but I'm getting this error:

g++ -O3 -Wall -std=c++11 -lX11 -L/usr/X11R6/lib -lm -pthread -MMD -MP -MF"src/per_iniziare.d" -MT"src/per_iniziare.d" -o "src/per_iniziare.o" "../src/per_iniziare.cpp"
    /tmp/cc1l38bP.o: In function `cimg_library::CImgDisplay::paint(bool) [clone .part.18]':
    per_iniziare.cpp:(.text+0x4f2): undefined reference to `XPutImage'
    per_iniziare.cpp:(.text+0x625): undefined reference to `XSendEvent'
    /tmp/cc1l38bP.o: In function `cimg_library::CImgDisplay::move(int, int) [clone .part.142]':
    per_iniziare.cpp:(.text+0x101a): undefined reference to `XMoveWindow'

As you can see, it looks like the proper libraries are linked

g++ -O3 -Wall -std=c++11 -lX11 -L/usr/X11R6/lib -lm -pthread [...]

and, indeed, if I try to compile the .cpp file manually in the terminal with

g++ -O3 -o try main.cpp -L/usr/X11R6/lib -lm -lX11 -pthread

it works perfectly.

I also tried to specify the libraries by going to Project > Properties > C/C++ Build > Settings, but nothing changes.

eclipse build settings

leqo
  • 356
  • 4
  • 15
  • 1
    The compiler call that you pasted is weird. It looks like an ordinary gcc call to compile just one translation unit (it aims to produce an `.o` file, yet gcc is not executed with `-c` flag). Please check if you have not changed the flags in C++ Compiler settings. If you did you should at least add an `-c` flag. It is very important for the build process. – luantkow Jan 19 '18 at 23:20
  • After that make sure that you still have the libraries and Library search path added in the `GCC C++ Linker`s Libraries section. – luantkow Jan 19 '18 at 23:31
  • Yeah it was that, I removed it while I was trying to figure out a solution. Then, I forgot to restore it after the manual inclusion of the libraries. Thank you very much for your help, thanks a lot – leqo Jan 20 '18 at 01:26

0 Answers0