X11 Problems when using CImg header in XCode on Mac OSX 10.11.6

后端 未结 1 1517
有刺的猬
有刺的猬 2021-01-24 05:42

I added X11 to my header search paths, library search paths, and I linked the binary to the X11 library in the build settings and build phases in XCode however I am still gettin

1条回答
  •  南方客
    南方客 (楼主)
    2021-01-24 05:45

    I think you have your build settings a little incorrect. Here is a very simple program to get you started - you can choose to display PNG, TIFF or JPEG files by using libpng, libtiff or libjpeg which I am assuming you have installed using homebrew with:

    brew install libpng libjpeg libtiff
    

    Here is the code:

    #define cimg_display  1
    #define cimg_use_png  1
    #define cimg_use_tiff 1
    #define cimg_use_jpeg 1
    
    #include "CImg.h"
    using namespace cimg_library;
    
    int main() {
        // Load image
        CImg image("/Users/mark/Desktop/test.tif");
        
        // CImg image("/Users/mark/Desktop/test.png");
        // CImg image("/Users/mark/Desktop/test.jpg");
        // CImg image("/Users/mark/Desktop/test.pnm");
    
        image.display();
    }
    

    The only build settings needed are as follows:

    and

    The /Users/mark/src/CImg one is for the CImg.h header file I manage with git, keeping it in sync with the CImg distribution on GitHub.

    Note the following:

    • CImg can read NetPBM (PGM/PBM/PPM and actually PFM) images without any extra code or libraries or dependencies

    • CImg can read TIFF, PNG, JPEG without needing ImageMagick if you #define cimg_use_tiff or #define cimg_use_png or #define cimg_use_jpeg as long as you set the include path the library path and the library names as I have shown above.

    • CImg can read anything that ImageMagick can read if you install that package.

    0 讨论(0)
提交回复
热议问题