ClausKlein
(Claus Klein)
September 10, 2023, 6:21pm
1
With this CMakeLists.txt
cmake_minimum_required(VERSION 3.21...3.27)
project(Hello VERSION 0.0.1 LANGUAGES CXX)
find_package(fmt REQUIRED)
add_executable(${PROJECT_NAME} main.cpp)
target_link_libraries(${PROJECT_NAME} fmt::fmt)
install(TARGETS ${PROJECT_NAME} DESTINATION bin)
install(IMPORTED_RUNTIME_ARTIFACTS fmt::fmt RUNTIME_DEPENDENCY_SET fmt RUNTIME)
install(RUNTIME_DEPENDENCY_SET fmt RUNTIME DESTINATION lib)
#XXX set(CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS "/usr/local/opt/fmt/lib/libfmt.10.dylib")
include(InstallRequiredSystemLibraries)
include(CPack)
I obtain the following CPack
package contents:
bash-5.2$ unzip Hello-0.0.1-Darwin.zip
Archive: Hello-0.0.1-Darwin.zip
creating: Hello-0.0.1-Darwin/bin/
inflating: Hello-0.0.1-Darwin/bin/Hello
creating: Hello-0.0.1-Darwin/lib/
linking: Hello-0.0.1-Darwin/lib/libfmt.10.1.0.dylib -> ../Cellar/fmt/10.1.1/lib/libfmt.10.1.0.dylib
linking: Hello-0.0.1-Darwin/lib/libfmt.10.dylib -> ../Cellar/fmt/10.1.1/lib/libfmt.10.dylib
finishing deferred symbolic links:
Hello-0.0.1-Darwin/lib/libfmt.10.1.0.dylib -> ../Cellar/fmt/10.1.1/lib/libfmt.10.1.0.dylib
Hello-0.0.1-Darwin/lib/libfmt.10.dylib -> ../Cellar/fmt/10.1.1/lib/libfmt.10.dylib
bash-5.2$
But I want to get all dependent dylib’s and the symlink targets too!
bash-5.2$ dyld_info -dependents build/Release/Hello
build/Release/Hello [x86_64]:
-dependents:
attributes load path
/usr/local/opt/fmt/lib/libfmt.10.dylib
/usr/lib/libc++.1.dylib
/usr/lib/libSystem.B.dylib
bash-5.2$
ClausKlein
(Claus Klein)
September 11, 2023, 5:36pm
2
Also under Linux, no system runtime files are installed?
bash-5.2$ docker run -ti --rm devcontainer:latest
root@c13334153f51:/home/app# ll
total 248
drwxr-xr-x 1 root root 4096 Sep 11 17:32 ./
drwxr-xr-x 1 root root 4096 Sep 11 17:32 ../
-rw-r--r-- 1 root root 223747 Sep 11 17:32 Hello-0.0.1-Linux.tar.gz
drwxr-xr-x 2 root root 4096 Sep 11 17:32 bin/
drwxr-xr-x 3 root root 4096 Sep 11 17:32 include/
drwxr-xr-x 4 root root 4096 Sep 11 17:32 lib/
drwxr-xr-x 5 root root 4096 Sep 11 17:32 stagedir/
root@c13334153f51:/home/app# ll lib
total 204
drwxr-xr-x 4 root root 4096 Sep 11 17:32 ./
drwxr-xr-x 1 root root 4096 Sep 11 17:32 ../
drwxr-xr-x 3 root root 4096 Sep 11 17:32 cmake/
lrwxrwxrwx 1 root root 12 Sep 11 17:32 libfmt.so -> libfmt.so.10
lrwxrwxrwx 1 root root 16 Sep 11 17:32 libfmt.so.10 -> libfmt.so.10.1.0
-rw-r--r-- 1 root root 192016 Sep 11 17:32 libfmt.so.10.1.0
drwxr-xr-x 2 root root 4096 Sep 11 17:32 pkgconfig/
root@c13334153f51:/home/app# ll stagedir/lib/
total 8368
drwxr-xr-x 4 root root 4096 Sep 11 17:32 ./
drwxr-xr-x 5 root root 4096 Sep 11 17:32 ../
drwxr-xr-x 3 root root 4096 Sep 11 17:32 cmake/
-rw-r--r-- 1 root root 283 Sep 11 17:32 libc.so
-rw-r--r-- 1 root root 2216304 Sep 11 17:32 libc.so.6
lrwxrwxrwx 1 root root 12 Sep 11 17:32 libfmt.so -> libfmt.so.10
lrwxrwxrwx 1 root root 16 Sep 11 17:32 libfmt.so.10 -> libfmt.so.10.1.0
-rw-r--r-- 1 root root 192016 Sep 11 17:32 libfmt.so.10.1.0
-rw-r--r-- 1 root root 141896 Sep 11 17:32 libgcc_s.so.1
-rw-r--r-- 1 root root 140 Sep 11 17:32 libm.so
-rw-r--r-- 1 root root 940560 Sep 11 17:32 libm.so.6
-rw-r--r-- 1 root root 2522584 Sep 11 17:32 libstdc++.so.6
-rw-r--r-- 1 root root 2522584 Sep 11 17:32 libstdc++.so.6.0.32
drwxr-xr-x 2 root root 4096 Sep 11 17:32 pkgconfig/
root@c13334153f51:/home/app# tar tzvf Hello-0.0.1-Linux.tar.gz
drwxr-xr-x root/root 0 2023-09-11 17:32 Hello-0.0.1-Linux/lib/
-rw-r--r-- root/root 192016 2023-09-11 17:32 Hello-0.0.1-Linux/lib/libfmt.so.10.1.0
drwxr-xr-x root/root 0 2023-09-11 17:32 Hello-0.0.1-Linux/lib/pkgconfig/
-rw-r--r-- root/root 229 2023-09-11 17:32 Hello-0.0.1-Linux/lib/pkgconfig/fmt.pc
lrwxrwxrwx root/root 0 2023-09-11 17:32 Hello-0.0.1-Linux/lib/libfmt.so.10 -> libfmt.so.10.1.0
drwxr-xr-x root/root 0 2023-09-11 17:32 Hello-0.0.1-Linux/lib/cmake/
drwxr-xr-x root/root 0 2023-09-11 17:32 Hello-0.0.1-Linux/lib/cmake/fmt/
-rw-r--r-- root/root 999 2023-09-11 17:32 Hello-0.0.1-Linux/lib/cmake/fmt/fmt-config.cmake
-rw-r--r-- root/root 1862 2023-09-11 17:32 Hello-0.0.1-Linux/lib/cmake/fmt/fmt-config-version.cmake
-rw-r--r-- root/root 814 2023-09-11 17:32 Hello-0.0.1-Linux/lib/cmake/fmt/fmt-targets-release.cmake
-rw-r--r-- root/root 4422 2023-09-11 17:32 Hello-0.0.1-Linux/lib/cmake/fmt/fmt-targets.cmake
lrwxrwxrwx root/root 0 2023-09-11 17:32 Hello-0.0.1-Linux/lib/libfmt.so -> libfmt.so.10
drwxr-xr-x root/root 0 2023-09-11 17:32 Hello-0.0.1-Linux/bin/
-rwxr-xr-x root/root 16112 2023-09-11 17:32 Hello-0.0.1-Linux/bin/Hello
drwxr-xr-x root/root 0 2023-09-11 17:32 Hello-0.0.1-Linux/include/
drwxr-xr-x root/root 0 2023-09-11 17:32 Hello-0.0.1-Linux/include/fmt/
-rw-r--r-- root/root 9895 2023-09-11 17:32 Hello-0.0.1-Linux/include/fmt/xchar.h
-rw-r--r-- root/root 72610 2023-09-11 17:32 Hello-0.0.1-Linux/include/fmt/chrono.h
-rw-r--r-- root/root 13966 2023-09-11 17:32 Hello-0.0.1-Linux/include/fmt/std.h
-rw-r--r-- root/root 24267 2023-09-11 17:32 Hello-0.0.1-Linux/include/fmt/color.h
-rw-r--r-- root/root 73122 2023-09-11 17:32 Hello-0.0.1-Linux/include/fmt/format-inl.h
-rw-r--r-- root/root 20677 2023-09-11 17:32 Hello-0.0.1-Linux/include/fmt/printf.h
-rw-r--r-- root/root 19004 2023-09-11 17:32 Hello-0.0.1-Linux/include/fmt/compile.h
-rw-r--r-- root/root 163914 2023-09-11 17:32 Hello-0.0.1-Linux/include/fmt/format.h
-rw-r--r-- root/root 24258 2023-09-11 17:32 Hello-0.0.1-Linux/include/fmt/ranges.h
-rw-r--r-- root/root 13040 2023-09-11 17:32 Hello-0.0.1-Linux/include/fmt/os.h
-rw-r--r-- root/root 98378 2023-09-11 17:32 Hello-0.0.1-Linux/include/fmt/core.h
-rw-r--r-- root/root 6554 2023-09-11 17:32 Hello-0.0.1-Linux/include/fmt/ostream.h
-rw-r--r-- root/root 7418 2023-09-11 17:32 Hello-0.0.1-Linux/include/fmt/args.h
root@c13334153f51:/home/app# ldd bin/Hello
linux-vdso.so.1 (0x00007fff211ce000)
libfmt.so.10 => /home/app/stagedir/lib/libfmt.so.10 (0x00007faeadb54000)
libc.so.6 => /home/app/stagedir/lib/libc.so.6 (0x00007faead92c000)
libstdc++.so.6 => /home/app/stagedir/lib/libstdc++.so.6 (0x00007faead6bf000)
libgcc_s.so.1 => /home/app/stagedir/lib/libgcc_s.so.1 (0x00007faead69b000)
/lib64/ld-linux-x86-64.so.2 (0x00007faeadb85000)
libm.so.6 => /home/app/stagedir/lib/libm.so.6 (0x00007faead5b4000)
root@c13334153f51:/home/app#
ClausKlein
(Claus Klein)
September 11, 2023, 5:41pm
3
See my example project as linux docker build.
ClausKlein
(Claus Klein)
September 12, 2023, 7:05am
4
@ben.boeckel What is the difference between RUNTIME_DEPENDENCY_SET
and InstallRequiredSystemLibraries
module usage?
In our use case we build an executable on ubuntu 20.04
but with gcc-11
.
It has to be delivered to Linux Mint 20.1
with an older libstd++
installed.
So we need to install the required system runtime libraries too.
ben.boeckel
(Ben Boeckel (Kitware))
September 13, 2023, 6:23pm
5
One traverses the metadata in binaries to figure out what is needed. I don’t know the specifics of how IRSL
works.
I recommend building on an appropriately vintaged Red Hat machine and using their SCL magic toolchains that embed extra symbols in the binaries as needed while only runtime-requiring the base libraries. We use this to build ParaView with GCC 10 while still working on CentOS 7 base installs.
ClausKlein
(Claus Klein)
September 13, 2023, 7:22pm
6
ClausKlein
(Claus Klein)
September 13, 2023, 7:51pm
7
Thanks, but it works:
Claus-iMac:cpack clausklein$ docker build -f ./Dockerfile --tag=devcontainer:latest .
[+] Building 28.1s (15/15) FINISHED docker:desktop-linux
=> [internal] load build definition from Dockerfile 0.1s
=> => transferring dockerfile: 1.51kB 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 119B 0.0s
=> [internal] load metadata for docker.io/linuxmintd/mint20.1-amd64:latest 0.0s
=> [internal] load metadata for docker.io/library/ubuntu:20.04 1.2s
=> CACHED [runner 1/4] FROM docker.io/linuxmintd/mint20.1-amd64:latest 0.0s
=> [setup-cpp-ubuntu 1/2] FROM docker.io/library/ubuntu:20.04@sha256:33a5cc25d22c45900796a1aca487ad7a7cb09f09ea00b779e3b2026b4fc2faba 0.0s
=> [internal] load build context 0.0s
=> => transferring context: 41.09kB 0.0s
=> CACHED [setup-cpp-ubuntu 2/2] RUN apt-get update -qq && export DEBIAN_FRONTEND=noninteractive && apt-get install -y --no-install-recommends git wget gnupg ca-certificates 0.0s
=> [builder 1/3] COPY . /home/app 0.2s
=> [builder 2/3] WORKDIR /home/app 0.0s
=> [builder 3/3] RUN bash -c 'source ~/.cpprc && cmake --workflow --preset Release --fresh && tar --exclude=cmake --exclude=pkgconfig -czvf stagedir.tar.gz stagedir/lib 18.6s
=> [runner 2/4] COPY --from=builder /home/app/*.tar.gz /home/app/ 0.4s
=> [runner 3/4] WORKDIR /home/app/ 0.1s
=> [runner 4/4] RUN bash -c 'tar -xzvf stagedir.tar.gz --strip-components 1' 1.6s
=> exporting to image 0.1s
=> => exporting layers 0.1s
=> => writing image sha256:0d31d8e1c283c4578ac1816b5e011a8e0d9ae12fb9abb76424dee73ccd852c38 0.0s
=> => naming to docker.io/library/devcontainer:latest 0.0s
What's Next?
View summary of image vulnerabilities and recommendations → docker scout quickview
Claus-iMac:cpack clausklein$ docker run -it --rm devcontainer:latest
Hello, world!
Claus-iMac:cpack clausklein$