Dlib: ImportError undefined symbol cblas_ddot

Created on 10 Jul 2016  路  9Comments  路  Source: davisking/dlib

OS: Arch Linux 64bit

$ pkg-config --libs cblas
-L -lcblas -lblas
$ file /lib/libcblas.so
/lib/libcblas.so: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, BuildID[sha1]=016679535567a6065cc9f5d0cdcbeb3f5830aa93, stripped
$ nm -D /lib/libcblas.so | grep ddot
0000000000008a60 T cblas_ddot

CMake's output:

-- Found PkgConfig: /usr/bin/pkg-config (found version 0.29.1) 
-- Checking for module 'cblas'
--   Found cblas, version 3.6.1
-- Checking for module 'lapack'
--   Found lapack, version 3.6.1
-- Found BLAS and LAPACK via pkg-config

I see Dlib doesn't check for cblas_ddot if it finds BLAS using pkg-config https://github.com/davisking/dlib/blob/master/dlib/cmake_utils/cmake_find_blas.txt#L54. I added the lines checking for cblas_ddot before the return statement and CMake said it can't find cblas_ddot. According to this thread, I replaced CHECK_FUNCTION_EXISTS with CHECK_LIBRARY_EXISTS and CMake finally found cblas_ddot.

But I also wrote a simple C program to test cblas_ddot and it works fine. Which means even though Dlib does not check for cblas_dot, it should be able to find it at runtime. Right? I've checked _link.txt_ and whether cblas_ddot is found or not, cblas and lapack are linked. So there probably is a problem when packing Dlib into a shared library.

Most helpful comment

For fellow arch linux users, if anyone facing same issue as above and wondering what @mljli means, just replace ./dlib/cmake_utils/cmake_find_blas.txt line 48
set(blas_libraries "${BLAS_REFERENCE_LDFLAGS}")
with
set(blas_libraries "-lcblas;-lblas")

But make sure the output of
pkg-config --libs cblas
is
-L -lcblas -lblas

All 9 comments

Cool. So it didn't link right for some configuration of arch linux and you fixed cmake so it did?

Nope. It still doesn't work.

$ ldd dlib.so
    libblas.so.3 => /usr/lib/libblas.so.3 (0x00007f8c8c7d5000)
    liblapack.so.3 => /usr/lib/liblapack.so.3 (0x00007f8c8bf9b000)
$ nm -D /usr/lib/libblas.so.3 | grep ddot
000000000000f5a0 T ddot_
$ nm -D /usr/lib/liblapack.so.3 | grep ddot
                 U ddot_
$ nm -D /usr/lib/libcblas.so.3 | grep ddot | xclip
0000000000008a60 T cblas_ddot
                 U ddot_
0000000000008c20 T ddotsub_

It's clear now the final shared library got linked to libblas.so and not libcblas.so. cblas_ddot is only available in libcblas.so. Maybe we could replace cblas_ddot with ddot_ which is available in all the three files. But why is libcblas.so not linked?

I don't know. Maybe there is something wrong with pkgconfig.

Uff..you're right. The output of pkg-config contains a -L with no argument and -lcblas follows it. Maybe gcc treated -lcblas as the argument of -L and that's why libcblas.so is not linked. Never encountered this before. Removing -L and it works now :)

Sweet

For fellow arch linux users, if anyone facing same issue as above and wondering what @mljli means, just replace ./dlib/cmake_utils/cmake_find_blas.txt line 48
set(blas_libraries "${BLAS_REFERENCE_LDFLAGS}")
with
set(blas_libraries "-lcblas;-lblas")

But make sure the output of
pkg-config --libs cblas
is
-L -lcblas -lblas

@ixna Any idea how to go about this when installing dlib trough pip?

What exactly is the conclusion here? pkgconfig on arch linux is broken and shouldn't be used at all? Maybe it should just be removed from the cmake script all together. I've never been a big fan of pkgconfig anyway.

I "solved" the issue for now by installing the python-dlib package from AUR and reinstalling my pipenv dependencies

Was this page helpful?
0 / 5 - 0 ratings

Related issues

alison-carrera-pegasus picture alison-carrera-pegasus  路  3Comments

yourmailhacked picture yourmailhacked  路  3Comments

pliablepixels picture pliablepixels  路  4Comments

farazirfan47 picture farazirfan47  路  5Comments

mohsin512 picture mohsin512  路  5Comments