Skip to content

ImportError undefined symbol cblas_ddot #154

Closed
@krsfrodaslz

Description

@krsfrodaslz
Contributor

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.

Activity

davisking

davisking commented on Jul 10, 2016

@davisking
Owner

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

krsfrodaslz

krsfrodaslz commented on Jul 10, 2016

@krsfrodaslz
ContributorAuthor

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?

davisking

davisking commented on Jul 10, 2016

@davisking
Owner

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

krsfrodaslz

krsfrodaslz commented on Jul 10, 2016

@krsfrodaslz
ContributorAuthor

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 :)

davisking

davisking commented on Jul 10, 2016

@davisking
Owner

Sweet

ixna

ixna commented on Aug 18, 2016

@ixna

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

yn5

yn5 commented on Nov 12, 2018

@yn5

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

davisking

davisking commented on Nov 12, 2018

@davisking
Owner

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.

yn5

yn5 commented on Nov 12, 2018

@yn5

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @yn5@ixna@davisking@krsfrodaslz

        Issue actions

          ImportError undefined symbol cblas_ddot · Issue #154 · davisking/dlib