链接器无法在 Alpine 上找到外部库(如 xcb 和 xkbcommon)

Linker can't find external libraries on Alpine (like xcb and xkbcommon)

我正在尝试使用 egui on Alpine Linux. It depends on xcb and xkbcommon 构建一个 Rust 应用程序,这两个应用程序都 link 分别命名为系统库。

我安装了这些系统库 libxcblibxkbcommon

$ file /usr/lib/libxcb.so.1.1.0
/usr/lib/libxcb.so.1.1.0: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, stripped
$ file /usr/lib/libxkbcommon.so.0.0.0
/usr/lib/libxkbcommon.so.0.0.0: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, stripped

cargo build 编译一切正常,但最终在 linking 阶段失败并出现以下错误:

   Compiling demo v0.1.0 (/home/tobtobxx/demo)
error: linking with `cc` failed: exit status: 1
  |
  = note: "cc" "-m64" "/home/tobtobxx/demo/target/debug/deps/demo-993544ecc00eea3c.1072hvf47tuvrufp.rcgu.o" "/home/tobtobxx/demo/target/debug/deps/demo-993544ecc00eea3c.1207ba842267saj8.rcgu.o" "/home/tobtobxx/demo/target/debug/deps/demo-993544ecc00eea3c.12t4nys80ep5ok64.rcgu.o" "/home/tobtobxx/demo/target/debug/deps/demo-993544ecc00eea3c.15sr8wbp6vbavn77.rcgu.o" "/home/tobtobxx/demo/target/debug/deps/demo-993544ecc00eea3c.168z1lbgn3mibm3y.rcgu.o" "/home/tobtobxx/demo/target/debug/deps/demo-993544ecc00eea3c.16owecqf00a8x2ih.rcgu.o" "/home/tobtobxx/demo/target/debug/deps/demo-993544ecc00eea3c.1ses8eo6dtiipjcg.rcgu.o" "/home/tobtobxx/demo/target/debug/deps/demo-993544ecc00eea3c.22z95m9twjnecuhx.rcgu.o" "/home/tobtobxx/demo/target/debug/deps/demo-993544ecc00eea3c.241ddb8cniczghpq.rcgu.o" "/home/tobtobxx/demo/target/debug/deps/demo-993544ecc00eea3c.25bkfhz09cvmaefj.rcgu.o" "/home/tobtobxx/demo/target/debug/deps/demo-993544ecc00eea3c.3476mec2ycy5zk9s.rcgu.o" "/home/tobtobxx/demo/target/debug/deps/demo-993544ecc00eea3c.3ko2zdms8dqv0mox.rcgu.o" "/home/tobtobxx/demo/target/debug/deps/demo-993544ecc00eea3c.42lrmbuspbssvzvg.rcgu.o" "/home/tobtobxx/demo/target/debug/deps/demo-993544ecc00eea3c.4domb26ispaq9y7v.rcgu.o" "/home/tobtobxx/demo/target/debug/deps/demo-993544ecc00eea3c.4tr9tcni38zutq2u.rcgu.o" "/home/tobtobxx/demo/target/debug/deps/demo-993544ecc00eea3c.5dxa2emkklmjrtuq.rcgu.o" "/home/tobtobxx/demo/target/debug/deps/demo-993544ecc00eea3c.89mjmp3m0wjxnup.rcgu.o" "/home/tobtobxx/demo/target/debug/deps/demo-993544ecc00eea3c.jy8d7onf0x3ty2o.rcgu.o" "/home/tobtobxx/demo/target/debug/deps/demo-993544ecc00eea3c.30afxwtgpit5h4lr.rcgu.o" "-Wl,--as-needed" "-L" "/home/tobtobxx/demo/target/debug/deps" "-L" "/usr/lib/rustlib/x86_64-alpine-linux-musl/lib" "-Wl,-Bstatic" "/home/tobtobxx/demo/target/debug/deps/libeframe-4989d4ffb29a1148.rlib" "/home/tobtobxx/demo/target/debug/deps/libegui_glium-1fa0acc60dc99165.rlib" "/home/tobtobxx/demo/target/debug/deps/libwebbrowser-f7d1ff5e26db8071.rlib" "/home/tobtobxx/demo/target/debug/deps/libcopypasta-1a70b72d4dd986d0.rlib" "/home/tobtobxx/demo/target/debug/deps/libx11_clipboard-5164615458bf0927.rlib" "/home/tobtobxx/demo/target/debug/deps/libxcb-6ed3b5bf7d8f5bab.rlib" "/home/tobtobxx/demo/target/debug/deps/libsmithay_clipboard-ea7a00bf367b0284.rlib" "/home/tobtobxx/demo/target/debug/deps/libsmithay_client_toolkit-49bc122a5cecabe6.rlib" "/home/tobtobxx/demo/target/debug/deps/libmemmap2-cbf0de1e03423aba.rlib" "/home/tobtobxx/demo/target/debug/deps/libglium-4c683ebf8dc91c00.rlib" "/home/tobtobxx/demo/target/debug/deps/libbacktrace-cfe5640a6b65a1c6.rlib" "/home/tobtobxx/demo/target/debug/deps/libminiz_oxide-29a5555ff4fcf977.rlib" "/home/tobtobxx/demo/target/debug/deps/libadler-5a5bfa8c46a05114.rlib" "/home/tobtobxx/demo/target/debug/deps/libobject-02dda4177be65a82.rlib" "/home/tobtobxx/demo/target/debug/deps/libaddr2line-33dd2a72642be146.rlib" "/home/tobtobxx/demo/target/debug/deps/libgimli-4db8f43d1fd0c10c.rlib" "/home/tobtobxx/demo/target/debug/deps/librustc_demangle-e04f12c9f4ecbed4.rlib" "/home/tobtobxx/demo/target/debug/deps/libtakeable_option-a160bd7a6386374e.rlib" "/home/tobtobxx/demo/target/debug/deps/libglutin-0fb1d6ef2feaa61d.rlib" "/home/tobtobxx/demo/target/debug/deps/libwayland_egl-30d4ad159e7bd0dd.rlib" "/home/tobtobxx/demo/target/debug/deps/libosmesa_sys-2ef8ce3641257762.rlib" "/home/tobtobxx/demo/target/debug/deps/libshared_library-7d009834354b8b52.rlib" "/home/tobtobxx/demo/target/debug/deps/libwinit-713aae18d1e4d872.rlib" "/home/tobtobxx/demo/target/debug/deps/libmio_misc-f572e828a70ea75e.rlib" "/home/tobtobxx/demo/target/debug/deps/libmio-9be73333ba1098b0.rlib" "/home/tobtobxx/demo/target/debug/deps/libcrossbeam-bc177022b1629607.rlib" "/home/tobtobxx/demo/target/debug/deps/libcrossbeam_channel-0330d3726534351b.rlib" "/home/tobtobxx/demo/target/debug/deps/libcrossbeam_deque-8db0a21294508fee.rlib" "/home/tobtobxx/demo/target/debug/deps/libcrossbeam_queue-4980c7cc2ec172cc.rlib" "/home/tobtobxx/demo/target/debug/deps/libcrossbeam_epoch-ca440741476fb33b.rlib" "/home/tobtobxx/demo/target/debug/deps/libmemoffset-0cd8794721e3c741.rlib" "/home/tobtobxx/demo/target/debug/deps/libcrossbeam_utils-d2e95f2e3a2c96d3.rlib" "/home/tobtobxx/demo/target/debug/deps/libpercent_encoding-4b51dd26890dc7a3.rlib" "/home/tobtobxx/demo/target/debug/deps/libsmithay_client_toolkit-61b91486be8d46d0.rlib" "/home/tobtobxx/demo/target/debug/deps/libandrew-8345ae44bbbaf0b7.rlib" "/home/tobtobxx/demo/target/debug/deps/libxml-392fa7ac39d23be1.rlib" "/home/tobtobxx/demo/target/debug/deps/libxdg-7d2e049b7e8255f9.rlib" "/home/tobtobxx/demo/target/debug/deps/libdirs-862b47f9cc72e360.rlib" "/home/tobtobxx/demo/target/debug/deps/libwalkdir-cff8f1f83f637836.rlib" "/home/tobtobxx/demo/target/debug/deps/libsame_file-18c70aef3e2c9c0b.rlib" "/home/tobtobxx/demo/target/debug/deps/librusttype-4ba0235917450376.rlib" "/home/tobtobxx/demo/target/debug/deps/libowned_ttf_parser-066a9bd8a0fc8eea.rlib" "/home/tobtobxx/demo/target/debug/deps/libttf_parser-289da127540b4ae9.rlib" "/home/tobtobxx/demo/target/debug/deps/libwayland_cursor-77574cc4d78022d1.rlib" "/home/tobtobxx/demo/target/debug/deps/libxcursor-1c3cf8f59b20a117.rlib" "/home/tobtobxx/demo/target/debug/deps/libnom-9c5059e91f2e381c.rlib" "/home/tobtobxx/demo/target/debug/deps/libminimal_lexical-ef953eff2e67d076.rlib" "/home/tobtobxx/demo/target/debug/deps/libmemchr-4247bd70778ed224.rlib" "/home/tobtobxx/demo/target/debug/deps/libmemmap2-3150b7f7c5b7a015.rlib" "/home/tobtobxx/demo/target/debug/deps/libwayland_protocols-c676e3f64a636f22.rlib" "/home/tobtobxx/demo/target/debug/deps/libwayland_client-52105033d131ff49.rlib" "/home/tobtobxx/demo/target/debug/deps/libscoped_tls-48ebc00917045d6c.rlib" "/home/tobtobxx/demo/target/debug/deps/libwayland_commons-c2a12da40eb47473.rlib" "/home/tobtobxx/demo/target/debug/deps/libnix-7afe16283c2b9cf5.rlib" "/home/tobtobxx/demo/target/debug/deps/libwayland_sys-2301e7db48efdf80.rlib" "/home/tobtobxx/demo/target/debug/deps/libdlib-f6f8248b705c1316.rlib" "/home/tobtobxx/demo/target/debug/deps/liblibloading-2508c0bb5f8bbad4.rlib" "/home/tobtobxx/demo/target/debug/deps/libcalloop-778145de583a548c.rlib" "/home/tobtobxx/demo/target/debug/deps/libnix-1884726b2f24c707.rlib" "/home/tobtobxx/demo/target/debug/deps/libcfg_if-20fa5e8234d15e90.rlib" "/home/tobtobxx/demo/target/debug/deps/libdlib-0b2b34f755320f8d.rlib" "/home/tobtobxx/demo/target/debug/deps/liblibloading-78dedecd30d289f9.rlib" "/home/tobtobxx/demo/target/debug/deps/libraw_window_handle-c33a1695ad15ccc6.rlib" "/home/tobtobxx/demo/target/debug/deps/libparking_lot-7dce2ef4725b88de.rlib" "/home/tobtobxx/demo/target/debug/deps/libparking_lot_core-1cd3f0ea76587e8d.rlib" "/home/tobtobxx/demo/target/debug/deps/libsmallvec-92f9120614b43f66.rlib" "/home/tobtobxx/demo/target/debug/deps/liblock_api-96ad05840b143ee7.rlib" "/home/tobtobxx/demo/target/debug/deps/libscopeguard-252ff94dc28f262b.rlib" "/home/tobtobxx/demo/target/debug/deps/libinstant-3f385258cf3a4033.rlib" "/home/tobtobxx/demo/target/debug/deps/libbitflags-d713298d8bf99b8f.rlib" "/home/tobtobxx/demo/target/debug/deps/liblog-7542b23b5f2148b6.rlib" "/home/tobtobxx/demo/target/debug/deps/libglutin_glx_sys-60225adf6fc4f6a5.rlib" "/home/tobtobxx/demo/target/debug/deps/libx11_dl-96d627acada51e95.rlib" "/home/tobtobxx/demo/target/debug/deps/libglutin_egl_sys-e1369188505371bf.rlib" "/home/tobtobxx/demo/target/debug/deps/libfnv-0b33398ce6e36ba9.rlib" "/home/tobtobxx/demo/target/debug/deps/liblazy_static-b9e0256d1e5b5240.rlib" "/home/tobtobxx/demo/target/debug/deps/libepi-25312c72f109a1aa.rlib" "/home/tobtobxx/demo/target/debug/deps/libegui-d92140ccc856b00f.rlib" "/home/tobtobxx/demo/target/debug/deps/libepaint-fa64446bf7d2ef46.rlib" "/home/tobtobxx/demo/target/debug/deps/libordered_float-954934b3ad340e58.rlib" "/home/tobtobxx/demo/target/debug/deps/libnum_traits-54cf8a1de773e101.rlib" "/home/tobtobxx/demo/target/debug/deps/libab_glyph-5c71f36475655ab5.rlib" "/home/tobtobxx/demo/target/debug/deps/libowned_ttf_parser-f769d1ba0186c5d5.rlib" "/home/tobtobxx/demo/target/debug/deps/libttf_parser-c2a059c3f6cc077b.rlib" "/home/tobtobxx/demo/target/debug/deps/libab_glyph_rasterizer-39ffe3a1656829a9.rlib" "/home/tobtobxx/demo/target/debug/deps/libahash-3453e66e36854ee1.rlib" "/home/tobtobxx/demo/target/debug/deps/libgetrandom-d0533091befb2114.rlib" "/home/tobtobxx/demo/target/debug/deps/liblibc-77e70a7dd1ff73e7.rlib" "/home/tobtobxx/demo/target/debug/deps/libcfg_if-c50eac2cacb45e19.rlib" "/home/tobtobxx/demo/target/debug/deps/libonce_cell-e0b7da911204eecc.rlib" "/home/tobtobxx/demo/target/debug/deps/libatomic_refcell-491ea045afd7a870.rlib" "/home/tobtobxx/demo/target/debug/deps/libemath-318ea50c7c682043.rlib" "-Wl,--start-group" "/usr/lib/rustlib/x86_64-alpine-linux-musl/lib/libstd-5f6b040e9cfd685d.rlib" "/usr/lib/rustlib/x86_64-alpine-linux-musl/lib/libpanic_unwind-93df834a6bbe8a40.rlib" "/usr/lib/rustlib/x86_64-alpine-linux-musl/lib/libminiz_oxide-5c681b793e14c088.rlib" "/usr/lib/rustlib/x86_64-alpine-linux-musl/lib/libadler-988868614816d05f.rlib" "/usr/lib/rustlib/x86_64-alpine-linux-musl/lib/libobject-6eda8ed657b8261b.rlib" "/usr/lib/rustlib/x86_64-alpine-linux-musl/lib/libaddr2line-05f636fa87f81883.rlib" "/usr/lib/rustlib/x86_64-alpine-linux-musl/lib/libgimli-6574a219d3f3e8cb.rlib" "/usr/lib/rustlib/x86_64-alpine-linux-musl/lib/libstd_detect-546ff2d8f1428e5a.rlib" "/usr/lib/rustlib/x86_64-alpine-linux-musl/lib/librustc_demangle-da7ea0d89dcd7897.rlib" "/usr/lib/rustlib/x86_64-alpine-linux-musl/lib/libhashbrown-6fb572f7d4249c90.rlib" "/usr/lib/rustlib/x86_64-alpine-linux-musl/lib/librustc_std_workspace_alloc-4a0fca16d9efa61c.rlib" "/usr/lib/rustlib/x86_64-alpine-linux-musl/lib/libunwind-29b050c6846dd49f.rlib" "/usr/lib/rustlib/x86_64-alpine-linux-musl/lib/libcfg_if-6019c80c727e1f36.rlib" "/tmp/rustc2tcxR8/liblibc-b1b9365f6e2d82fa.rlib" "/usr/lib/rustlib/x86_64-alpine-linux-musl/lib/liballoc-f6412179823aa29a.rlib" "/usr/lib/rustlib/x86_64-alpine-linux-musl/lib/librustc_std_workspace_core-d53f9648e14d116a.rlib" "/usr/lib/rustlib/x86_64-alpine-linux-musl/lib/libcore-2e098f72274253b6.rlib" "-Wl,--end-group" "/usr/lib/rustlib/x86_64-alpine-linux-musl/lib/libcompiler_builtins-332f4948dca82247.rlib" "-Wl,-Bdynamic" "-lxcb" "-lxcb-render" "-lxcb-shape" "-lxcb-xfixes" "-lxkbcommon" "-ldl" "-lssp_nonshared" "-lgcc_s" "-lc" "-Wl,--eh-frame-hdr" "-Wl,-znoexecstack" "-L" "/usr/lib/rustlib/x86_64-alpine-linux-musl/lib" "-o" "/home/tobtobxx/demo/target/debug/deps/demo-993544ecc00eea3c" "-Wl,--gc-sections" "-pie" "-Wl,-zrelro" "-Wl,-znow" "-nodefaultlibs" "-Wl,-rpath,$ORIGIN/../../../../usr/lib/rustlib/x86_64-alpine-linux-musl/lib" "-Wl,--enable-new-dtags"
  = note: /usr/lib/gcc/x86_64-alpine-linux-musl/10.3.1/../../../../x86_64-alpine-linux-musl/bin/ld: cannot find -lxcb
          /usr/lib/gcc/x86_64-alpine-linux-musl/10.3.1/../../../../x86_64-alpine-linux-musl/bin/ld: cannot find -lxcb-render
          /usr/lib/gcc/x86_64-alpine-linux-musl/10.3.1/../../../../x86_64-alpine-linux-musl/bin/ld: cannot find -lxcb-shape
          /usr/lib/gcc/x86_64-alpine-linux-musl/10.3.1/../../../../x86_64-alpine-linux-musl/bin/ld: cannot find -lxcb-xfixes
          /usr/lib/gcc/x86_64-alpine-linux-musl/10.3.1/../../../../x86_64-alpine-linux-musl/bin/ld: cannot find -lxkbcommon
          collect2: error: ld returned 1 exit status


error: could not compile `demo` due to previous error

这表明 linker 无法找到这些库。但它们确实存在于所有其他图书馆存在的地方。

我可以在我的 Archlinux 系统上完美地构建相同的 Rust 代码,我也在其中安装了这些依赖项。

我发现 Alpine 系统的一个特点是它们不同步 link /lib/usr/lib。难道linker只在/lib搜索?我如何 (a) 验证和 (b) 更正?

要 link 反对 libxcb.so(或其他库),您需要有这个文件(即不是 libxcb.so.1 或其他特定版本)。

因为通常只需要用于开发目的,Alpine 在 -dev 包中提供了这些符号 link。

运行

apk add libxcb-dev libxkbcommon-dev

帮我修好了。