Problem with library search paths and cmake and debian bullseye

I did build a custom “clang” v14.0.6 in a debian “bullseye” virtual machine. It works in this VM. It works in Ubuntu. It works in github workflows. But it does not work in a docker container, that is based on… “bullseye”…
Makes no sense to me, but it is what it is. So what does not work in that node container ?

This very small cmake project:

cmake_minimum_required(VERSION 3.18)

project( foo C)

find_library( PTHREADS_LIBRARY NAMES pthreads pthread)
message( STATUS "PTHREADS_LIBRARY=${PTHREADS_LIBRARY}")

When I run it with cmake -DCMAKE_C_COMPILER=gcc . the pthreads library is found:

cmake -DCMAKE_C_COMPILER=gcc .
-- The C compiler identification is GNU 10.2.1
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/gcc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- PTHREADS_LIBRARY=/usr/lib/x86_64-linux-gnu/libpthread.so
-- Configuring done
-- Generating done
-- Build files have been written to: /xxx

but when I use “my” clang, it doesn’t work (again: it works fine in bullseye, where it was built)

rm CMakeCache.txt
cmake -DCMAKE_C_COMPILER=mulle-clang .
-- The C compiler identification is Clang 14.0.6
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/mulle-clang - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- PTHREADS_LIBRARY=PTHREADS_LIBRARY-NOTFOUND
-- Configuring done
-- Generating done
-- Build files have been written to: /xxx

The compiler search directories are OK though:

mulle-clang -print-search-dirs | egrep libraries
libraries: =/opt/mulle-clang-project/14.0.6.2/lib/clang/14.0.6:/opt/mulle-clang-project/14.0.6.2/bin/../lib/x86_64-unknown-linux-gnu:/usr/bin/../lib/gcc/x86_64-linux-gnu/10:/lib/x86_64-linux-gnu:/lib/../lib64:/usr/lib/x86_64-linux-gnu:/lib:/usr/lib

The compiler (that uses the system linker anyway) itself, has no problems:

cat <<EOF > x.c
#include <pthread.h>


int  main()
{
   return( pthread_self());
}
EOF
mulle-clang -o x x.c -lpthread

To make a long story longer, here is the cmake find_library debug output:

With gcc:

  find_library called with the following settings:

    VAR: PTHREADS_LIBRARY
    NAMES: "pthreads"
           "pthread"
    Documentation: Path to a library.
    Framework
      Only Search Frameworks: 0
      Search Frameworks Last: 0
      Search Frameworks First: 0
    AppBundle
      Only Search AppBundle: 0
      Search AppBundle Last: 0
      Search AppBundle First: 0
    CMAKE_FIND_USE_CMAKE_PATH: 1
    CMAKE_FIND_USE_CMAKE_ENVIRONMENT_PATH: 1
    CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH: 1
    CMAKE_FIND_USE_CMAKE_SYSTEM_PATH: 1

  find_library considered the following locations:

    /usr/local/sbin/(lib)pthreads(\.so|\.a)
    /usr/local/bin/(lib)pthreads(\.so|\.a)
    /usr/sbin/(lib)pthreads(\.so|\.a)
    /usr/bin/(lib)pthreads(\.so|\.a)
    /sbin/(lib)pthreads(\.so|\.a)
    /bin/(lib)pthreads(\.so|\.a)
    /usr/local/lib/x86_64-linux-gnu/(lib)pthreads(\.so|\.a)
    /usr/local/lib/(lib)pthreads(\.so|\.a)
    /usr/local/(lib)pthreads(\.so|\.a)
    /usr/lib/x86_64-linux-gnu/(lib)pthreads(\.so|\.a)
    /usr/lib/(lib)pthreads(\.so|\.a)
    /usr/(lib)pthreads(\.so|\.a)
    /lib/x86_64-linux-gnu/(lib)pthreads(\.so|\.a)
    /lib/(lib)pthreads(\.so|\.a)
    /usr/X11R6/lib/x86_64-linux-gnu/(lib)pthreads(\.so|\.a)
    /usr/X11R6/lib/(lib)pthreads(\.so|\.a)
    /usr/X11R6/(lib)pthreads(\.so|\.a)
    /usr/pkg/lib/x86_64-linux-gnu/(lib)pthreads(\.so|\.a)
    /usr/pkg/lib/(lib)pthreads(\.so|\.a)
    /usr/pkg/(lib)pthreads(\.so|\.a)
    /opt/lib/x86_64-linux-gnu/(lib)pthreads(\.so|\.a)
    /opt/lib/(lib)pthreads(\.so|\.a)
    /opt/(lib)pthreads(\.so|\.a)
    /usr/lib/X11/(lib)pthreads(\.so|\.a)
    /usr/local/sbin/(lib)pthread(\.so|\.a)
    /usr/local/bin/(lib)pthread(\.so|\.a)
    /usr/sbin/(lib)pthread(\.so|\.a)
    /usr/bin/(lib)pthread(\.so|\.a)
    /sbin/(lib)pthread(\.so|\.a)
    /bin/(lib)pthread(\.so|\.a)
    /usr/local/lib/x86_64-linux-gnu/(lib)pthread(\.so|\.a)
    /usr/local/lib/(lib)pthread(\.so|\.a)
    /usr/local/(lib)pthread(\.so|\.a)

  The item was found at

    /usr/lib/x86_64-linux-gnu/libpthread.so

with mulle-clang (same if -DCMAKE_LINKER=ld set)

  find_library called with the following settings:

    VAR: PTHREADS_LIBRARY
    NAMES: "pthreads"
           "pthread"
    Documentation: Path to a library.
    Framework
      Only Search Frameworks: 0
      Search Frameworks Last: 0
      Search Frameworks First: 0
    AppBundle
      Only Search AppBundle: 0
      Search AppBundle Last: 0
      Search AppBundle First: 0
    CMAKE_FIND_USE_CMAKE_PATH: 1
    CMAKE_FIND_USE_CMAKE_ENVIRONMENT_PATH: 1
    CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH: 1
    CMAKE_FIND_USE_CMAKE_SYSTEM_PATH: 1

  find_library considered the following locations:

    /usr/local/sbin/(lib)pthreads(\.so|\.a)
    /usr/local/bin/(lib)pthreads(\.so|\.a)
    /usr/sbin/(lib)pthreads(\.so|\.a)
    /usr/bin/(lib)pthreads(\.so|\.a)
    /sbin/(lib)pthreads(\.so|\.a)
    /bin/(lib)pthreads(\.so|\.a)
    /usr/local/lib/x86_64-unknown-linux-gnu/(lib)pthreads(\.so|\.a)
    /usr/local/lib/(lib)pthreads(\.so|\.a)
    /usr/local/(lib)pthreads(\.so|\.a)
    /usr/lib/x86_64-unknown-linux-gnu/(lib)pthreads(\.so|\.a)
    /usr/lib/(lib)pthreads(\.so|\.a)
    /usr/(lib)pthreads(\.so|\.a)
    /lib/x86_64-unknown-linux-gnu/(lib)pthreads(\.so|\.a)
    /lib/(lib)pthreads(\.so|\.a)
    /usr/X11R6/lib/x86_64-unknown-linux-gnu/(lib)pthreads(\.so|\.a)
    /usr/X11R6/lib/(lib)pthreads(\.so|\.a)
    /usr/X11R6/(lib)pthreads(\.so|\.a)
    /usr/pkg/lib/x86_64-unknown-linux-gnu/(lib)pthreads(\.so|\.a)
    /usr/pkg/lib/(lib)pthreads(\.so|\.a)
    /usr/pkg/(lib)pthreads(\.so|\.a)
    /opt/lib/x86_64-unknown-linux-gnu/(lib)pthreads(\.so|\.a)
    /opt/lib/(lib)pthreads(\.so|\.a)
    /opt/(lib)pthreads(\.so|\.a)
    /usr/lib/X11/(lib)pthreads(\.so|\.a)
    /usr/local/sbin/(lib)pthread(\.so|\.a)
    /usr/local/bin/(lib)pthread(\.so|\.a)
    /usr/sbin/(lib)pthread(\.so|\.a)
    /usr/bin/(lib)pthread(\.so|\.a)
    /sbin/(lib)pthread(\.so|\.a)
    /bin/(lib)pthread(\.so|\.a)
    /usr/local/lib/x86_64-unknown-linux-gnu/(lib)pthread(\.so|\.a)
    /usr/local/lib/(lib)pthread(\.so|\.a)
    /usr/local/(lib)pthread(\.so|\.a)
    /usr/lib/x86_64-unknown-linux-gnu/(lib)pthread(\.so|\.a)
    /usr/lib/(lib)pthread(\.so|\.a)
    /usr/(lib)pthread(\.so|\.a)
    /lib/x86_64-unknown-linux-gnu/(lib)pthread(\.so|\.a)
    /lib/(lib)pthread(\.so|\.a)
    /usr/X11R6/lib/x86_64-unknown-linux-gnu/(lib)pthread(\.so|\.a)
    /usr/X11R6/lib/(lib)pthread(\.so|\.a)
    /usr/X11R6/(lib)pthread(\.so|\.a)
    /usr/pkg/lib/x86_64-unknown-linux-gnu/(lib)pthread(\.so|\.a)
    /usr/pkg/lib/(lib)pthread(\.so|\.a)
    /usr/pkg/(lib)pthread(\.so|\.a)
    /opt/lib/x86_64-unknown-linux-gnu/(lib)pthread(\.so|\.a)
    /opt/lib/(lib)pthread(\.so|\.a)
    /opt/(lib)pthread(\.so|\.a)
    /usr/lib/X11/(lib)pthread(\.so|\.a)

  The item was not found.

So /usr/lib/x86_64-unknown-linux-gnu/(lib)pthreads(\.so|\.a) would be the ticket, except that it should be /usr/lib/x86_64-linux-gnu/(lib)pthreads(\.so|\.a). The “unknown-” is killing me, but there does it come from ?

The cmake versions on “bullseye” and “node” are identical (3.18.4). I am stumped.


Here is the container Dockerfile:

FROM node:16-bullseye-slim

RUN DEBIAN_FRONTEND=noninteractive \
   apt-get update \
   && apt-get -y install curl build-essential cmake uuid-runtime git lsb-release libpthread-stubs0-dev \
   && curl -L -O "https://github.com/mulle-cc/mulle-clang-project/releases/download/14.0.6.2/mulle-clang-14.0.6.2-bullseye-amd64.deb" \
   && dpkg --install "mulle-clang-14.0.6.2-bullseye-amd64.deb"

Hello, I face same issue. The problem in cmake comes from the introduction of the directory lib/x86_64-unknown-linux-gnu in clang. Now clang uses by default -L<clang-bin-path>/../lib/x86_64-unknown-linux-gnu. Cmake is taking the CMAKE_LIBRARY_ARCHITECTURE from the first directory in this call. By this your CMAKE_LIBRARY_ARCHITECTURE will always be x86_64-unknown-linux-gnu (instead of x86_64-linux-gnu on Ubuntu). find_library will not find libraries anymore which are placed under /usr/lib/x86_64-linux-gnu