Menu

Can't compile examples on Mac OS X

Help
yellowbkpk
2014-12-28
2015-01-02
  • yellowbkpk

    yellowbkpk - 2014-12-28

    When following the example compilation instructions on dlib.net, I run into an error with a bunch of lines similar to this:

    Undefined symbols for architecture x86_64:
      "jpeg_std_error(jpeg_error_mgr*)", referenced from:
          dlib::jpeg_loader::read_image(char const*) in libdlib.a(jpeg_loader.o)
    

    The complete compile log is here: https://gist.github.com/iandees/316df0bfd6733fc02607

    Obviously I'm missing a JPEG library somewhere, but I don't know which one is needed or where it needs to go.

    Thanks in advance!

     

    Last edit: yellowbkpk 2014-12-28
    • Davis

      Davis - 2014-12-28

      There must be something wrong with the copy of libjpeg installed on your
      system. I have CMake setup to automatically find and link to the system
      wide installed libjpeg or, if it can't be found, then it compiles the copy
      of libjpeg included in dlib/external into your application. In your case,
      CMake is finding it on your system and then linking to it but it doesn't
      have the required link symbols.

      If you comment out the line that says find_package(JPEG QUIET) in
      dlib/CMakeLists.txt then CMake won't look on your system and will compile
      its own copy of libjpeg. That's a little screwy though. The best thing to
      do is to fix your system, which may be as simple as downloading libjpeg's
      source and running a ./configure; make; make install to install it.

      Cheers,
      Davis

       
  • yellowbkpk

    yellowbkpk - 2014-12-28

    Homebrew put jpeg-8d at /usr/local/Cellar/jpeg/8d/lib/:

    $ ls /usr/local/Cellar/jpeg/8d/lib/
    libjpeg.8.dylib libjpeg.a       libjpeg.dylib
    

    What is cmake doing to search for it? Can I tell it where the library is?

     
    • Davis

      Davis - 2014-12-29

      I'm not sure what cmake is doing to search for it but it must have found a
      copy somewhere on your system given the output you pasted. However, that
      version of it is missing important symbols or is compiled in some
      inappropriate way. I'm under the impression that mac supports both 32bit
      and 64bit binaries on the same system. So maybe libjpeg is compiled as a
      32bit library rather than as a 64bit library.

       
  • Davis

    Davis - 2014-12-30

    I just changed dlib's cmake file to check if the installed libjpeg contains the correct linker symbols and if not to compile it from scratch to make sure everything works. You can grab it from github (https://github.com/davisking/dlib/blob/master/dlib/CMakeLists.txt). This should hopefully sidestep any problems you are having.

     

    Last edit: Davis 2014-12-30
  • yellowbkpk

    yellowbkpk - 2015-01-01

    I cloned from Github and am getting the same error:

    $ git clone git@github.com:davisking/dlib.git
    $ cd dlib/examples
    $ mkdir build
    $ cd build
    $ cmake ..
    $ cmake --build .
    [ 39%] Built target dlib
    [ 39%] Built target assignment_learning_ex
    [ 40%] Built target bayes_net_ex
    [ 41%] Built target bayes_net_from_disk_ex
    [ 42%] Built target bayes_net_gui_ex
    [ 42%] Built target bridge_ex
    [ 43%] Built target bsp_ex
    [ 44%] Built target compress_stream_ex
    [ 45%] Built target config_reader_ex
    [ 45%] Built target custom_trainer_ex
    [ 46%] Built target dir_nav_ex
    [ 46%] Built target empirical_kernel_map_ex
    Linking CXX executable face_detection_ex
    Undefined symbols for architecture x86_64:
      "jpeg_std_error(jpeg_error_mgr*)", referenced from:
          dlib::jpeg_loader::read_image(char const*) in libdlib.a(jpeg_loader.o)
      "jpeg_stdio_src(jpeg_decompress_struct*, __sFILE*)", referenced from:
          dlib::jpeg_loader::read_image(char const*) in libdlib.a(jpeg_loader.o)
      "jpeg_read_header(jpeg_decompress_struct*, int)", referenced from:
          dlib::jpeg_loader::read_image(char const*) in libdlib.a(jpeg_loader.o)
      "jpeg_read_scanlines(jpeg_decompress_struct*, unsigned char**, unsigned int)", referenced from:
          dlib::jpeg_loader::read_image(char const*) in libdlib.a(jpeg_loader.o)
      "jpeg_CreateDecompress(jpeg_decompress_struct*, int, unsigned long)", referenced from:
          dlib::jpeg_loader::read_image(char const*) in libdlib.a(jpeg_loader.o)
      "jpeg_start_decompress(jpeg_decompress_struct*)", referenced from:
          dlib::jpeg_loader::read_image(char const*) in libdlib.a(jpeg_loader.o)
      "jpeg_finish_decompress(jpeg_decompress_struct*)", referenced from:
          dlib::jpeg_loader::read_image(char const*) in libdlib.a(jpeg_loader.o)
      "jpeg_destroy_decompress(jpeg_decompress_struct*)", referenced from:
          dlib::jpeg_loader::read_image(char const*) in libdlib.a(jpeg_loader.o)
    ld: symbol(s) not found for architecture x86_64
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    make[2]: *** [face_detection_ex] Error 1
    make[1]: *** [CMakeFiles/face_detection_ex.dir/all] Error 2
    make: *** [all] Error 2
    
     
    • Davis

      Davis - 2015-01-01

      What is the output when you first generate the makefile with cmake? It
      should say this somewhere in it:
      -- Looking for png_create_read_struct
      -- Looking for png_create_read_struct - found
      -- Looking for jpeg_read_header
      -- Looking for jpeg_read_header - found

       
  • yellowbkpk

    yellowbkpk - 2015-01-01

    Yep, got this:

    -- Looking for png_create_read_struct
    -- Looking for png_create_read_struct - found
    -- Looking for jpeg_read_header
    -- Looking for jpeg_read_header - found
    
     
    • Davis

      Davis - 2015-01-01

      lol, naturally. I don't what what the deal is with the new OS X. If you
      replace line 277 in dlib/CMakeLists.txt

           if (JPEG_FOUND AND LIBJPEG_IS_GOOD)
      

      with

           if (JPEG_FOUND AND LIBJPEG_IS_GOOD AND NOT APPLE)
      

      it should definitely compile since that avoids linking to the system's
      libjpeg all together. So does that work?

       
  • yellowbkpk

    yellowbkpk - 2015-01-01

    That worked, thanks! Now I need to figure out how to train my sign detector...

     
    • Davis

      Davis - 2015-01-02

      Cool. I'll commit that change.

       

Log in to post a comment.