Hi,
i'm programing in CodeBlocks (http://www.codeblocks.org/). I would like to add Dlib (http://dlib.net/) library to my project.
How can I do this?
I went to my project "Build options..."->"Search directories"->Compiler and added path to "dlib" folder.
I did the same for "Linker" and "Resource compiler"
(more info abaut adding libaries (general))
I copied code from this page http://dlib.net/image_ex.cpp.html and I got errors.

After that I copied dlib folder inside project and now my proyect can find dlib library. :)
But I still have some errors.

C:\Projekti\SlikaCGIbin\main.cpp|68|undefined reference to dlib::base_window::set_title(std::string const&)'| C:\Projekti\SlikaCGIbin\main.cpp|75|undefined reference todlib::base_window::wait_until_closed() const'|
C:\Projekti\SlikaCGIbin\main.cpp|76|undefined reference to `dlib::base_window::wait_until_closed() const'|
...

Dani AI

Generated

As discovered, the compiler finding the dlib headers only fixes include-time errors — those "undefined reference" messages mean the dlib implementation was never linked. and are right in direction: you either need a compiled dlib library or you must compile dlib's implementation into your project.

Two practical fixes that work reliably:

  1. Build dlib as a library with the same toolchain you use for your Code::Blocks project (MinGW/g++ or MSVC). Use CMake in the dlib source tree to generate a Makefile or Visual Studio project, build it, then add the produced library file (libdlib.a or dlib.lib/dll) to the project linker settings (or give the full path to the .a/.lib). Example (MinGW):
mkdir build
cd build
cmake .. -G "MinGW Makefiles"
mingw32-make
  1. Compile the implementation into the executable. Many dlib releases include a single translation-unit that pulls in the implementation (commonly something like dlib/all/source.cpp). Add that .cpp to your Code::Blocks project so it is compiled alongside main.cpp — no separate library step needed.

Troubleshooting and cautions: always build dlib with the same compiler and architecture (32 vs 64 bit) as your project; mixing MSVC-built libs with MinGW projects (or 32/64 mismatches) causes link failures. If using image, BLAS/CUDA, or format support, link those external libs too. To verify the built library actually contains the symbol, use:

nm -C path/to/libdlib.a | grep base_window

or on MSVC toolchain:

dumpbin /symbols path\to\dlib.lib | findstr base_window

Finally, ensure the library entry is present in Code::Blocks Linker settings (or add the full library file path) and that the linker search directory points to it; correct build of the library or adding the single dlib implementation TU will eliminate the undefined references.

Recommended Answers

All 2 Replies

It sounds like you set up the search directories fine, but doesn't seem like you actually linked the required libraries. Right next to the Search directories tab is the Linker settings tab, click this and then press the add button and add the required libraries to your project (you can just type in the name of the libraries so long as you have set the search directory for the linker right to the root folder of all of the dlib libraries).

Go to Project-->Build Options-->Linker Settings tab, then click the Add button so that you can add the name of the file. Libraries must be in the format libXXX.a, same as in unix gcc or g++

After looking at the link you posted all you will get is the source files -- no libraries. So you will have to compile and build it yourself. There should be a doc file that tells you how to do that.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.