Menu

Trouble installing Dlib for python on Mac OSX 10.10

Help
Rohan B
2015-08-11
2015-08-12
  • Rohan B

    Rohan B - 2015-08-11

    I'm trying to install dlib-18.16 for python on my computer (running Mac OSX 10.10). I have boost python installed as well as X11, but I've been running into trouble when running ./compile_dlib_python_module.bat as instructed to after downloading the files.

    The errors I get are numerous, but look something like this

    [ 1%] Building CXX object dlib_build/CMakeFiles/dlib.dir/gui_widgets/fonts.o
    In file included from /Users/xxx/Downloads/dlib-18.16/dlib/gui_widgets/fonts.cpp:14:
    /Users/xxx/Downloads/dlib-18.16/dlib/gui_widgets/nativefont.h:313:21: error: use
    of undeclared identifier 'XAllocColor'
    XAllocColor(d, cmap, &xcol);
    This continues for a while and ends with

    /Users/xxx/Downloads/dlib-18.16/dlib/gui_widgets/nativefont.h:400:21: error: use
    of undeclared identifier 'XFillRectangle'
    XFillRectangle(d, pix, gc, 0, 0, width, height);
    ^
    fatal error: too many errors emitted, stopping now [-ferror-limit=]
    20 errors generated.
    make[2]: [dlib_build/CMakeFiles/dlib.dir/gui_widgets/fonts.o] Error 1
    make[1]:
    [dlib_build/CMakeFiles/dlib.dir/all] Error 2
    make: *** [all] Error 2

    I've checked for some of the missing functions like XFillRectangle, and found them declared in some .h files in the anaconda install of python (when looking at the dlib_build files, the installer seems to have located the anaconda install). Does anyone have any ideas as to how to fix this?

     
    • Davis

      Davis - 2015-08-11

      Those are X11 symbols. If you are getting those errors then X11 isn't
      installed correctly. Did you install XQuartz?

       
  • Rohan B

    Rohan B - 2015-08-11

    yes I did, it's there in my /usr/ folder

     
    • Davis

      Davis - 2015-08-11

      Do the C++ example programs compile or is it just python?

       
  • Rohan B

    Rohan B - 2015-08-11

    I haven't been able to build the c++ version either, I get the same errors

     
    • Davis

      Davis - 2015-08-11

      Huh. How did you install XQuartz?

       
  • Rohan B

    Rohan B - 2015-08-11

    I downloaded it from here:

    http://xquartz.macosforge.org/landing/

     
    • Davis

      Davis - 2015-08-11

      What exactly did you type to compile the c++ examples and what was the
      output?

       
  • Rohan B

    Rohan B - 2015-08-11

    I typed the following from the dlib directory.

    cd examples
    mkdir build
    cd build
    cmake ..
    cmake --build . --config Release

    After the last command, I get the following

    [ 1%] Building CXX object dlib_build/CMakeFiles/dlib.dir/gui_widgets/fonts.o
    In file included from /Users/xxx/Downloads/dlib-18.16/dlib/gui_widgets/fonts.cpp:14:
    /Users/xxx/Downloads/dlib-18.16/dlib/gui_widgets/nativefont.h:313:21: error:
    use of undeclared identifier 'XAllocColor'
    XAllocColor(d, cmap, &xcol);
    ^
    /Users/xxx/Downloads/dlib-18.16/dlib/gui_widgets/nativefont.h:319:36: error:
    use of undeclared identifier 'XmbTextExtents'; did you mean
    'XTextExtents'?
    return XmbTextExtents(fs, str, len, ink, logical);
    ^~~~~~~~~~~~~~
    XTextExtents
    /Users/xxx/Downloads/dlib-18.16/dlib/gui_widgets/nativefont.h:318:43: note:
    'XTextExtents' declared here
    inline static int XTextExtents (XFontSet fs, cha...
    ^
    /Users/xxx/Downloads/dlib-18.16/dlib/gui_widgets/nativefont.h:322:36: error:
    use of undeclared identifier 'XwcTextExtents'; did you mean
    'XTextExtents'?
    return XwcTextExtents(fs, str, len, ink, logical);
    ^~~~~~~~~~~~~~
    XTextExtents
    /Users/xxx/Downloads/dlib-18.16/dlib/gui_widgets/nativefont.h:321:43: note:
    'XTextExtents' declared here
    inline static int XTextExtents (XFontSet fs, wch...
    ^
    /Users/xxx/Downloads/dlib-18.16/dlib/gui_widgets/nativefont.h:325:29: error:
    use of undeclared identifier 'XmbDrawString'; did you mean 'XDrawString'?
    XmbDrawString(d, w, fs, gc, x, y, str, num_bytes);
    ^~~~~~~~~~~~~
    XDrawString
    /Users/xxx/Downloads/dlib-18.16/dlib/gui_widgets/nativefont.h:324:44: note:
    'XDrawString' declared here
    inline static void XDrawString(Display d, Windo...
    ^
    /Users/xxx/Downloads/dlib-18.16/dlib/gui_widgets/nativefont.h:328:29: error:
    use of undeclared identifier 'XwcDrawString'; did you mean 'XDrawString'?
    XwcDrawString(d, w, fs, gc, x, y, str, num_bytes);
    ^~~~~~~~~~~~~
    XDrawString
    /Users/xxx/Downloads/dlib-18.16/dlib/gui_widgets/nativefont.h:327:44: note:
    'XDrawString' declared here
    inline static void XDrawString(Display
    d, Windo...
    ^
    /Users/xxx/Downloads/dlib-18.16/dlib/gui_widgets/nativefont.h:334:29: error:
    use of undeclared identifier 'XOpenDisplay'
    d = XOpenDisplay(NULL);
    ^
    /Users/xxx/Downloads/dlib-18.16/dlib/gui_widgets/nativefont.h:337:33: error:
    use of undeclared identifier 'XOpenDisplay'
    d = XOpenDisplay(":0.0");
    ^
    /Users/xxx/Downloads/dlib-18.16/dlib/gui_widgets/nativefont.h:369:29: error:
    use of undeclared identifier 'XFreeFontSet'
    XFreeFontSet(d, fs);
    ^
    /Users/xxx/Downloads/dlib-18.16/dlib/gui_widgets/nativefont.h:371:30: error:
    use of undeclared identifier 'XCreateFontSet'
    fs = XCreateFontSet(d, fontset, &mlist, &mcount...
    ^
    /Users/xxx/Downloads/dlib-18.16/dlib/gui_widgets/nativefont.h:376:34: error:
    use of undeclared identifier 'XExtentsOfFontSet'
    extent = XExtentsOfFontSet(fs);
    ^
    /Users/xxx/Downloads/dlib-18.16/dlib/gui_widgets/nativefont.h:379:25: error:
    use of undeclared identifier 'XFreeStringList'; did you mean
    'XwcFreeStringList'?
    XFreeStringList(mlist);
    ^~~~~~~~~~~~~~~
    XwcFreeStringList
    /Users/xxx/anaconda/include/X11/Xutil.h:777:13: note: 'XwcFreeStringList'
    declared here
    extern void XwcFreeStringList(
    ^
    In file included from /Users/xxx/Downloads/dlib-18.16/dlib/gui_widgets/fonts.cpp:14:
    /Users/xxx/Downloads/dlib-18.16/dlib/gui_widgets/nativefont.h:379:41: error:
    cannot initialize a parameter of type 'wchar_t ' with an lvalue of type
    'char
    '
    XFreeStringList(mlist);
    ^~~~~
    /Users/xxx/anaconda/include/X11/Xutil.h:781:1: note: passing argument to
    parameter here
    );
    ^
    In file included from /Users/xxx/Downloads/dlib-18.16/dlib/gui_widgets/fonts.cpp:14:
    /Users/xxx/Downloads/dlib-18.16/dlib/gui_widgets/nativefont.h:388:29: error:
    use of undeclared identifier 'XFreeGC'
    XFreeGC(d, gc);
    ^
    /Users/xxx/Downloads/dlib-18.16/dlib/gui_widgets/nativefont.h:389:29: error:
    use of undeclared identifier 'XFreePixmap'
    XFreePixmap(d, pix);
    ^
    /Users/xxx/Downloads/dlib-18.16/dlib/gui_widgets/nativefont.h:393:103: error:
    use of undeclared identifier 'XDefaultDepth'
    ...DefaultRootWindow(d), pix_width_prev, pix_height_prev, XDefaultDepth(d, ...
    ^
    /Users/xxx/Downloads/dlib-18.16/dlib/gui_widgets/nativefont.h:394:30: error:
    use of undeclared identifier 'XCreateGC'
    gc = XCreateGC(d, pix, 0, NULL);
    ^
    /Users/xxx/Downloads/dlib-18.16/dlib/gui_widgets/nativefont.h:398:21: error:
    use of undeclared identifier 'XSetForeground'
    XSetForeground(d, gc, backcolor);
    ^
    /Users/xxx/Downloads/dlib-18.16/dlib/gui_widgets/nativefont.h:399:21: error:
    use of undeclared identifier 'XSetBackground'
    XSetBackground(d, gc, backcolor);
    ^
    /Users/xxx/Downloads/dlib-18.16/dlib/gui_widgets/nativefont.h:400:21: error:
    use of undeclared identifier 'XFillRectangle'
    XFillRectangle(d, pix, gc, 0, 0, width, height);
    ^
    fatal error: too many errors emitted, stopping now [-ferror-limit=]
    20 errors generated.
    make[2]: [dlib_build/CMakeFiles/dlib.dir/gui_widgets/fonts.o] Error 1
    make[1]:
    [dlib_build/CMakeFiles/dlib.dir/all] Error 2
    make: *** [all] Error 2

     
    • Davis

      Davis - 2015-08-11

      XAllocColor is a function in the X11 API. It should exist. Look in the
      folder that contains the X11 header files and see if any of them define
      that function. If not then something is deeply wrong with your X11
      install. It should be inside the X11/Xlib.h file.

       
  • Rohan B

    Rohan B - 2015-08-11

    I found this in /usr/X11/include/X11/Xlib.h

    extern Status XAllocColor(
    Display / display /,
    Colormap /
    colormap /,
    XColor
    / screen_in_out /
    );

    I'm assuming this is the declaration.

     
    • Davis

      Davis - 2015-08-11

      That's the one. Since you aren't getting a "I can't find X11/Xlib.h
      include file error" there must be another X11/Xlib.h file on your computer
      that is being #included instead and is missing that declaration. Search
      your computer for that file and see if it exists. Either that or there is
      some kind of preprocessor macro that is stripping it out.

      Here is an even simpler test. What happens when you type?
      cd examples
      g++ -I.. gui_api_ex.cpp ../dlib/all/source.cpp -lX11 -lpthread

       
  • Rohan B

    Rohan B - 2015-08-11

    I found a lot of Xlib.h files on my computer, including one in dlib/gui_core actually.

    I got the following error when running that command

    ld: library not found for -lX11
    clang: error: linker command failed with exit code 1 (use -v to see invocation)

     
    • Davis

      Davis - 2015-08-11

      Well, I don't have an OS X machine to test this out on. But I know lots of
      people who regularly use dlib on OSX and normally it's not an issue. It
      looks like something is wrong with your X11 install but I can't tell you
      what that is. I would try looking into cmake to see what folder it thinks
      Xlib.h is in and what X11 library it's trying to link to. Maybe it's not
      the one you expect.

       
  • Rohan B

    Rohan B - 2015-08-11

    I'm looking into CMakeCache.txt and it looks like the xlib path is going through my anaconda install of python. To change that, should I edit the txt file or another file?

     
  • Rohan B

    Rohan B - 2015-08-11

    Actually it looks like the anaconda version of Xlib.h includes a file called tkIntXlibDecls.h which has the XAllocColor function declared, so I have no idea what's up...

     
    • Davis

      Davis - 2015-08-11

      Try rerunning cmake with an option like -DCMAKE_INCLUDE_PATH=/usr/X11/include.
      Maybe that will get it to find the right file.

       
  • Rohan B

    Rohan B - 2015-08-11

    I'm confused, what should be the command exactly?

    Do you mean
    cmake .. - DCMAKE_INCLUDE_PATH=/usr/X11/include

     
    • Davis

      Davis - 2015-08-11

      Yeah, except without the space after the hyphen. You will also probably
      need to delete the contents of the build folder before doing it.

       
  • Rohan B

    Rohan B - 2015-08-11

    I tried your suggestion, and it compiled the C version. I had to run cmake without the '..' but with the DCMAKE flag. But I'm having trouble with the python version, still getting the same error

    Just for reference, here's what I'm running in the python_examples directory.

    mkdir build
    cd build
    cmake ../../tools/python -DCMAKE_INCLUDE_PATH=/usr/X11/include
    cmake --build . --config Release --target install

     

    Last edit: Rohan B 2015-08-11
  • Rohan B

    Rohan B - 2015-08-11

    I realized that I had to go into the CMakeCache.txt file and manually change the X11 path from anaconda to usr/X11. It works now, thank you for all your help!

     

    Last edit: Rohan B 2015-08-11
    • Davis

      Davis - 2015-08-11

      No problem.

      Out of curiosity, if you change this (near line 149 in dlib/CMakeLists.txt)

              find_path(xlib_path Xlib.h
                 PATHS
                 /Developer/SDKs/MacOSX10.4u.sdk/usr/X11R6/include
                 PATH_SUFFIXES X11
                 )
      

      to

              find_path(xlib_path Xlib.h
                 PATHS
                 /Developer/SDKs/MacOSX10.4u.sdk/usr/X11R6/include
                 /usr/wherever/you/found/the/right/one
                 PATH_SUFFIXES X11
                 )
      

      Does it make it so it compiles without needing to modify the CMakeCache.txt
      file?

       
  • Rohan B

    Rohan B - 2015-08-12

    It did not work for python unfortunately

     
    • Davis

      Davis - 2015-08-12

      When you look at what happened, did xlib_path end up with the right path or
      still get the anaconda one?

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.