CImg doesn't recognize png/jpeg macOS

259 Views Asked by At

I'm new using, CImg I already installed CImg using brew install cimg, and then I installed XQuartz. When I'm trying to run this program in the terminal I get this error:

Code:

#include <iostream>
#include "CImg.h"

using namespace cimg_library;
using namespace std;

int main() {
    CImg<unsigned char> A("img.png");
    A.display();
    return 0;
}

Error:

[CImg] *** CImgIOException *** [instance(0,0,0,0,0x0,non-shared)] CImg<unsigned char>::load(): Failed to recognize format of file 'img.png'.
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 'img.png'.

And when I'm trying running the same code with #define cimg_use_png 1 over the #include "CImg.h" I get this linker error

Solution: This is the proper way to compile the file. g++ -std=c++11 main.cpp -o main -I /opt/X11/include -L /opt/X11/lib -lX11 -ljpeg -lpng -lz. Source And the #define cimg_use_png 1 should be there.

0

There are 0 best solutions below