davisking / dlib

A toolkit for making real world machine learning and data analysis applications in C++
http://dlib.net
Boost Software License 1.0
13.57k stars 3.38k forks source link

CMake: Set LAPACK libs as public #2923

Closed jschueller closed 7 months ago

jschueller commented 8 months ago

lapack/cblas libs are needed through the dlib/matrix/lapack headers

it can be verified on the optimization example: https://github.com/jschueller/dlib-cmake-example

davisking commented 8 months ago

What's the issue exactly? I don't totally follow. All the stuff I know about compiles fine how it is on master. The example you linked to just looks like the examples in dlib's repository. But something is different?

jschueller commented 8 months ago

the problem is the executable fails to link if I dont explicitely link to LAPACK (https://github.com/jschueller/dlib-cmake-example/blob/main/CMakeLists.txt#L15; but it should not be needed and work out of the box by linking to the dlib::dlib exported target):

[ 25%] Building CXX object CMakeFiles/optim_ex.dir/optimization_ex.cpp.o
[ 50%] Linking CXX executable optim_ex
/usr/bin/ld: CMakeFiles/optim_ex.dir/optimization_ex.cpp.o: undefined reference to symbol 'cblas_dger'
/usr/bin/ld: /usr/lib/libcblas.so.3: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
davisking commented 8 months ago

Are you sure you are using the current version of dlib for this?

jschueller commented 8 months ago

yes, master, but I should add that this only happens when compiling dlib as a shared library (dlib defaults to static isnt it ?)

davisking commented 8 months ago

Sure. Can you post exactly the commands to reproduce this? I tried building and install dlib as a shared library on ubuntu and building https://github.com/jschueller/dlib-cmake-example. It all built and ran fine. I git cloned the current master dlib though.

jschueller commented 8 months ago

yes, the example works because I manually link LAPACK; you can comment lines 14-15 to see the error: https://github.com/jschueller/dlib-cmake-example/blob/main/CMakeLists.txt#L14

davisking commented 8 months ago

Sorry, I meant to say I also deleted that line when I tested it.  So what’s the exact set of commands to reproduce this?On Mar 9, 2024, at 3:39 AM, Julien Schueller @.***> wrote: yes, the example works because I manually link LAPACK; you can comment lines 14-15 to see the error: https://github.com/jschueller/dlib-cmake-example/blob/main/CMakeLists.txt#L14

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you commented.Message ID: @.***>

jschueller commented 8 months ago

maybe you are using static lapack libs in dlib, in that case it wont show either.

jschueller commented 8 months ago

anyway, here is how to reproduce from a clean ubuntu install:

FROM ubuntu:22.04
ENV DEBIAN_FRONTEND=noninteractive MAKEFLAGS="-j8"

RUN apt-get -y update && apt-get install -y git g++ cmake liblapack-dev libjpeg-turbo8-dev libpng-dev zlib1g-dev

WORKDIR /tmp
RUN git clone --depth 1 https://github.com/davisking/dlib.git && cd dlib && cmake -B build -DBUILD_SHARED_LIBS=ON . && make install -C build -j12

RUN git clone https://github.com/jschueller/dlib-cmake-example.git && cd dlib-cmake-example && sed -i "s|LAPACK_LIBRARIES|skip|g" CMakeLists.txt && cmake . && make

which yields:

[100%] Linking CXX executable optim_ex
/usr/bin/ld: CMakeFiles/optim_ex.dir/optimization_ex.cpp.o: undefined reference to symbol 'dgetrf_'
/usr/bin/ld: /lib/x86_64-linux-gnu/liblapack.so.3: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/optim_ex.dir/build.make:99: optim_ex] Error 1
make[1]: *** [CMakeFiles/Makefile2:85: CMakeFiles/optim_ex.dir/all] Error 2
make: *** [Makefile:91: all] Error 2
davisking commented 7 months ago

Huh yeah, sorry for the late reply. And thanks for the PR :)