title: Docker build cmake multiple containers with same custom library
body: <p>I'll start off by saying that I'm new to Docker and a novice with cmake so forgive any ignorance.  I'm working on porting a series of applications and a single shared library to a docker environment.  From my understanding Docker does not play well with shared libraries so I'd need to static link.  My goal is to use docker-compose to build multiple different application containers but each of these containers using the same custom library (that was setup as a .so in previous environment).  I'm currently setup to do cross-compile w/ Docker and can build and run each app w/o the library.  Now I need to add in the library.</p>
  <p>Current folder/file setup is as follows:</p>
  <pre><code>app1:
    inc:
      app1.h &lt;--includes mysharedlib.h
    src:
      app1.cpp
    CMakeLists.txt
    custom-toolchain.cmake
    Dockerfile
  
  app2:
    inc:
      app2.h &lt;--includes mysharedlib.h
    src:
      app2.cpp
    CMakeLists.txt
    custom-toolchain.cmake
    Dockerfile
  
  MySharedLib:
    inc:
      mysharedlib.h
    src:
      mysharedlib.cpp
    custom-toolchain.cmake
    CMakeLists.txt
  </code></pre>
  <p>Can someone please help explain how I go about including the library into each container and how to include it correctly with CMake?</p>
  <p>current working app implementation is as follows:
  dockerfile for app1:</p>
  <pre><code>ARG IMAGE_TAG=2-bullseye
  ARG TOOLCHAIN_ARCH=aarch64
  ARG PKG_ARCH=arm64
  ARG IMAGE_ARCH=linux/arm64
  
  FROM torizon/debian-cross-toolchain-arm64:2-bullseye AS build
  
  ARG PKG_ARCH
  ARG TOOLCHAIN_ARCH
  
  RUN apt-get -y update &amp;&amp; apt-get install -y \
      cmake \
      python-dev \
      gcc \
      make \
      gcc \
      binutils \
      build-essential \
      wget\
      libasound2-dev:arm64 \
      &amp;&amp; apt-get clean &amp;&amp; apt-get autoremove &amp;&amp; rm -rf /var/lib/apt/lists/*
  
  WORKDIR /mypjsip
  RUN mkdir out_libs
  
  RUN wget https://github.com/pjsip/pjproject/archive/2.10.tar.gz &amp;&amp; tar -xvf 2.10.tar.gz
  RUN cd pjproject-2.10/ &amp;&amp; ./configure --host=aarch64-linux-gnu --disable-libwebrtc  &amp;&amp; make dep &amp;&amp; make &amp;&amp; make DESTDIR=/mypjsip/out_libs install
  
  COPY . app1_src
  COPY $TOOLCHAIN_ARCH-toolchain.cmake app1_src/$TOOLCHAIN_ARCH-toolchain.cmake
  RUN mkdir app1_src/build
  RUN cd app1_src/build &amp;&amp; cmake .. -DCMAKE_TOOLCHAIN_FILE=./$TOOLCHAIN_ARCH-toolchain.cmake
  RUN cd app1_src/build &amp;&amp; make install
  
  FROM --platform=linux/arm64 torizon/debian:$IMAGE_TAG
  RUN apt-get -y update &amp;&amp; apt-get install -y \
      libasound2 \
      alsa-utils \
      &amp;&amp; apt-get clean &amp;&amp; apt-get autoremove &amp;&amp; rm -rf /var/lib/apt/lists/*
  
  COPY --from=build /mypjsip/pjproject-2.10/pjsip-apps/bin/pjsua* /usr/local/bin/pjsua
  COPY --from=build /mypjsip/out_libs/* /
  COPY --from=build /usr/bin/app1 /usr/bin/
  
  ENTRYPOINT [ &quot;/usr/bin/app1&quot; ]
  </code></pre>
  <p>cmake for app1:</p>
  <pre><code>cmake_minimum_required(VERSION 3.13)
  
  project(app1)
  
  set(CMAKE_CXX_STANDARD 17)
  set(CMAKE_CXX_STANDARD_REQUIRED True)
  
  set(INC_DIR ./inc)
  include_directories(${INC_DIR})
  
  AUX_SOURCE_DIRECTORY(src SOURCE_FILES)
  
  add_executable(app1 ${SOURCE_FILES})
  
  set(WARNINGS &quot;\
  -pedantic \
  -pedantic-errors \
  -Wextra \
  -Wcast-align \
  -Wcast-qual \
  -Wdisabled-optimization \
  -Werror \
  -Wfloat-equal \
  -Wformat=2 \
  -Wformat-nonliteral \
  -Wformat-security  \
  -Wformat-y2k \
  -Wimport \
  -Winit-self \
  -Winline \
  -Winvalid-pch \
  -Wmissing-field-initializers \
  -Wmissing-format-attribute \
  -Wmissing-include-dirs \
  -Wmissing-noreturn \
  -Wpacked \
  -Wpointer-arith \
  -Wredundant-decls \
  -Wshadow \
  -Wstack-protector \
  -Wstrict-aliasing=2 \
  -Wswitch-default \
  -Wswitch-enum \
  -Wunreachable-code \
  -Wvariadic-macros \
  -Wwrite-strings&quot;)
  
  
  if ( CMAKE_COMPILER_IS_GNUCXX )
      set(CMAKE_CXX_FLAGS  &quot;${CMAKE_CXX_FLAGS} ${WARNINGS} &quot;)
  endif(CMAKE_COMPILER_IS_GNUCXX)
  
  set(CMAKE_INSTALL_PREFIX /usr)
  install(TARGETS app1 DESTINATION bin)
  </code></pre>