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.