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 getting the errors shown in the picture below. I am 99.999% Sure the problem is X11 because when I disable the display capabilities the warnings aren't there. Any ideas on what I can do next?
-
How exactly did you add X11 to your library search path? This is a linker error, so most likely the linker just can't find your X11 libraries. – saagarjha Jan 20 '18 at 23:11
-
Went to the Build Settings and added /opt/X11/include/ X11, /opt/X11/lib, /opt/X11/include in my header and library search paths and I went to the build phases and added X11 under "Link Binary with Libraries" – Tiffany Montgomery Jan 20 '18 at 23:34
-
Also the some of the paths included in the CImg file were incorrect. Like the XLib.h file path being X11/include/X11/XLib.h instead of just X11/XLib.h. I fixed all of that but I still get the same errors I posted here. – Tiffany Montgomery Jan 20 '18 at 23:36
-
Please show a screen grab of your linker settings. – Mark Setchell Jan 22 '18 at 21:23
-
@MarkSetchell Just edited. I'm also getting different errors now within the locale.h file. Will post those too. – Tiffany Montgomery Jan 22 '18 at 22:01
-
I presume you have installed **XQuartz**? – Mark Setchell Jan 22 '18 at 22:04
-
yep. I am able to compile the program with clang in the terminal. – Tiffany Montgomery Jan 22 '18 at 22:09
1 Answers
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<unsigned char> image("/Users/mark/Desktop/test.tif");
// CImg<unsigned char> image("/Users/mark/Desktop/test.png");
// CImg<unsigned char> image("/Users/mark/Desktop/test.jpg");
// CImg<unsigned char> 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.

- 1
- 1

- 191,897
- 31
- 273
- 432
-
Yay! That got rid of the locale errors! Now XCode can't find the XLib.h file though. The file is located in /opt/X11/include/X11/ but idk how to tell Xcode that... Update: If I replace the path included in CImg with the absolute path of the Xlib.h file it works. I feel like I shouldn't have to do that though since others haven't had to rewrite the CImg code. – Tiffany Montgomery Jan 23 '18 at 14:41
-
The `header search path` should be set to `/opt/X11/include` because inside `CImg.h` it does `#include
– Mark Setchell Jan 23 '18 at 14:57 -
What does it mean when the value
is next to the header search paths? I only typed in /opt/X11/include but its displaying multiple values. Would that have an affect? – Tiffany Montgomery Jan 23 '18 at 18:18 -
Just read your update. I get 20 more errors within the cwchar file (No member named "x" in the global namespace) after adding the new header and library paths. Is there something else I need to install? – Tiffany Montgomery Jan 23 '18 at 22:43
-
Just a guess, but have you tried putting all those headers under "User Header Search Paths"? – saagarjha Jan 24 '18 at 05:53
-
-
Could you maybe try creating a small, fresh, brand-new Xcode project, just with the suggested settings I gave you and the code I gave you? I fear you have maybe tried lots of different things in desperation and left something set to a non-default value... – Mark Setchell Jan 24 '18 at 13:56
-
I made a new project with the given settings and I got the same errors. I think the problem might be something outside of Xcode. I'm going to reinstall XQuartz and see if that makes a difference. – Tiffany Montgomery Jan 24 '18 at 20:16
-
If you have changed `CImg.h` grab a new copy of that too - it should not need changing at all. – Mark Setchell Jan 24 '18 at 20:25