I am given this code for a program called face_landmark_detection_ex. There is no makefile.

How can I find out what command I need to type in, in Ubuntu, to produce an executable that I can run?

I tried to compile it with:

 g++ face_landmark_detection_ex.cpp  -o face $(pkg-config --cflags --libs dlib)

But that returned:

   Package dlib was not found in the pkg-config search path.
   Perhaps you should add the directory containing `dlib.pc'
   to the PKG_CONFIG_PATH environment variable

And a ton loads of errors like:

   No package 'dlib' found
   In file included from /usr/local/include/dlib/geometry/rectangle.h:7:0,
                    from /usr/local/include/dlib/geometry.h:6,
                    from /usr/local/include/dlib/image_processing/object_detector.h:7,
                    from /usr/local/include/dlib/image_processing/frontal_face_detector.h:7,
                    from face_landmark_detection_ex.cpp:41:
   /usr/local/include/dlib/algs.h:17:10: error: #error "Dlib requires C++11 support.  Give your compiler the               -std=c++11 option to enable it."
            #error "Dlib requires C++11 support.  Give your compiler the -std=c++11
   In file included from /usr/include/c++/5/array:35:0,
                    from /usr/local/include/dlib/serialize.h:150,
                    from /usr/local/include/dlib/geometry/rectangle.h:10,
                    from /usr/local/include/dlib/geometry.h:6,
                    from /usr/local/include/dlib/image_processing/object_detector.h:7,
                    from /usr/local/include/dlib/image_processing/frontal_face_detector.h:7,
                    from face_landmark_detection_ex.cpp:41:
   /usr/include/c++/5/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support        for the ISO C++ 2011 standard. This support must be enabled with the -std=c++11 or -std=gnu++11 compiler               options.
    #error This file requires compiler and library support \

...and so forth.

I already did: sudo apt install libdlib-dev


Later, I tried running:

g++ face_landmark_detection_ex.cpp -l dlib -std=c++11 -o main

But that didn't seem to work. It produced these "undefined reference" errors, including for symbols in the dlib namespace. The full errors are in pastebin; here are the first few lines:

$ g++ face_landmark_detection_ex.cpp -l dlib -std=c++11 -o main
/tmp/ccY36F7N.o: In function `main':
face_landmark_detection_ex.cpp:(.text+0x15e): undefined reference to `dlib::image_window::image_window()'
face_landmark_detection_ex.cpp:(.text+0x16d): undefined reference to `dlib::image_window::image_window()'
face_landmark_detection_ex.cpp:(.text+0x431): undefined reference to `dlib::image_window::clear_overlay()'
face_landmark_detection_ex.cpp:(.text+0x4a1): undefined reference to `dlib::image_window::add_overlay(std::vector<dlib::image_display::overlay_line, std::allocator<dlib::image_display::overlay_line> > const&)'
face_landmark_detection_ex.cpp:(.text+0x5e3): undefined reference to `dlib::image_window::~image_window()'
face_landmark_detection_ex.cpp:(.text+0x5f2): undefined reference to `dlib::image_window::~image_window()'
face_landmark_detection_ex.cpp:(.text+0x773): undefined reference to `dlib::image_window::~image_window()'
face_landmark_detection_ex.cpp:(.text+0x78a): undefined reference to `dlib::image_window::~image_window()'
/tmp/ccY36F7N.o: In function `dlib::lapack::binding::gesdd(char, int, int, double*, int, double*, double*, int, double*, int, double*, int, int*)':
face_landmark_detection_ex.cpp:(.text._ZN4dlib6lapack7binding5gesddEciiPdiS2_S2_iS2_iS2_iPi[_ZN4dlib6lapack7binding5gesddEciiPdiS2_S2_iS2_iS2_iPi]+0x91): undefined reference to `dgesdd_'
  • 1
    Why would you need to know a command? It says "Perhaps you should add the directory containing `dlib.pc' to the PKG_CONFIG_PATH environment variable" Should that not be the 1st thing to do? See askubuntu.com/questions/210210/… for instance. – Rinzwind Jul 27 '17 at 15:09
  • @Rinzwind Although I already installed libdlib-dev, I tried 'locate dlib.pc' and it seems not to be present on my machine. – gihidoma Jul 27 '17 at 15:10
  • 1
    Ans the database for locate was updated after the installation? locate is not real time. – Rinzwind Jul 27 '17 at 15:12
  • @Rinzwind did: sudo apt update followed by locate dlib.pc: returned nothing – gihidoma Jul 27 '17 at 15:17
  • @Rinzwind OK just did sudo updatedb and found it in: /home/john/DLIB/dlib-19.4/dlib/cmake_utils/dlib.pc.in , how do I now go about compiling this source file? – gihidoma Jul 27 '17 at 15:33

You may be omitting some required -l flags, or you may be linking against the wrong version of dlib.

Besides -ldlib, you also need -llapack, -lblas, and -lgif.

This works for me on Ubuntu 16.04 LTS:

g++ -std=c++11 -o face_landmark_detection_ex face_landmark_detection_ex.cpp -llapack -lblas -ldlib -lgif

The output shown in your question indicates that, when you attempted to build the program, header files in /usr/local/include/dlib were found. This is not where the libdlib-dev package puts its header files, so the version of dlib you installed yourself, 19.4, is the one that is being used.

  • That is probably good. Not only is it newer, but I believe face_landmark_detection_ex is incompatible with Ubuntu's dlib because it is compiled with DLIB_NO_GUI_SUPPORT.
  • If you're not otherwise using the version of dlib provided by libdlib-dev and its dependencies, I recommend uninstalling them (see below).

Dlib is sometimes used without being installed, but it appears you installed it in /usr/local, perhaps with a method like the one given in step 3.1 here. Assuming you ran sudo ldconfig after installing it, and that the liblapack-dev, libblas-dev, and libgif-dev packages are installed, passing -llapack -lblas -ldlib -lgif to the compiler should produce a successful build:

ek@Io:~/src$ g++ -std=c++11 -o face_landmark_detection_ex face_landmark_detection_ex.cpp -llapack -lblas -ldlib -lgif
ek@Io:~/src$ ./face_landmark_detection_ex
Call this program like this:
./face_landmark_detection_ex shape_predictor_68_face_landmarks.dat faces/*.jpg

You can get the shape_predictor_68_face_landmarks.dat file from:

You may want to pass other flags to the compiler to enable warnings and (as the source code's comments mention) optimizations.

I tried omitting various combinations of flags to get different errors, but I was unable to produce the specific linker errors you got, so perhaps more is going on here.

Uninstalling the System-Provided Dlib

To ensure that the older version of dlib (from when you installed libdlib-dev) is not interfering, as well as to prevent confusion, I suggest uninstalling it. One problem this can help solve is the possibility that the compiler is using headers for the dlib version you installed but the linker is using the system-provided version of the library. They are not compatible with one another.

Assuming you installed the system-provided dlib by running sudo apt install libdlib-dev and no other Ubuntu software is depending on it, these commands will uninstall it:

sudo apt remove libdlib-dev
sudo apt autoremove

The -dev package provides just the header files, but it causes the library itself to be installed as a dependency; the autoremove action removes packages that are installed just to satisfy dependencies of other packages that have since been removed.

If after this the dependencies are not all installed, you can add them back. For example, you might have to run this:

sudo apt install liblapack-dev libblas-dev libgif-dev

(If you like, you could do that first, before removing packages, to mark them as manually installed and prevent them from being removed in the first place.)

Then, I suggest uninstalling and reinstalling the version of dlib you installed manually, though just running sudo ldconfig again might be sufficient, if the version you installed is in no way broken. It might not even be necessary, but it should not cause harm.

One benefit of rebuilding and reinstalling dlib is that you will likely be informed if some of its dependencies are no longer satisfied.

When you install Dlib again, it might give you the option of using its own built-in version of a library that it depends on or installing the system-provided library. For example, if liblapack-dev and libblas-dev aren't installed, it may suggest you install them. If it does, I recommend doing that--for one, you may get better performance--and start the Dlib build over again.

If you do this and you get the same errors--or different ones--then please update your question with more information.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.