From d48c73c7ba18227006b74560ef10f885a2c44995 Mon Sep 17 00:00:00 2001 From: Ethan Ligon Date: Sat, 25 Apr 2026 21:52:12 -0700 Subject: [PATCH] Statically link libstdc++/libgcc into Linux Node addon The published lbugjs.node currently dynamically links libstdc++, imposing a GLIBCXX version requirement on end users determined by the build host. On stable Linux distros (Debian 12, Ubuntu 22.04, RHEL 8/9 family), the system libstdc++ is older than what the GitHub-hosted runner provides, so loading the addon fails with: Error: /lib/.../libstdc++.so.6: version `GLIBCXX_3.4.31' not found (required by .../lbugjs.node) code: 'ERR_DLOPEN_FAILED' Add -static-libstdc++ -static-libgcc to the Linux link flags by default, gated behind a CMake option (LBUG_NODEJS_STATIC_LIBSTDCXX) so users who explicitly want a shared-libstdc++ addon can opt out. The static lib (liblbug.a) already statically links its own libstdc++ via the manylinux_2_28 + gcc-toolset-13 compat build, so this only affects the small addon shim. Tested locally on Debian 12 ARM: the resulting lbugjs.node depends only on libc, libm, and ld-linux, and loads without LD_LIBRARY_PATH or any compatibility shim. --- CMakeLists.txt | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 42de264..ee47738 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -116,4 +116,15 @@ if(APPLE) else() target_link_options(lbugjs PRIVATE -Wl,--export-dynamic) endif() + +# Statically link libstdc++ and libgcc on Linux so the published .node +# does not impose a GLIBCXX version requirement on end users. Without this, +# the prebuilt addon fails to load on stable distros (e.g. Debian 12, +# Ubuntu 22.04, RHEL 8/9) whose system libstdc++ is older than the build +# host's. Default ON; can be disabled for users who deliberately want a +# shared-libstdc++ addon. +option(LBUG_NODEJS_STATIC_LIBSTDCXX "Statically link libstdc++ and libgcc into the Node addon (Linux only)" ON) +if(UNIX AND NOT APPLE AND LBUG_NODEJS_STATIC_LIBSTDCXX) + target_link_options(lbugjs PRIVATE -static-libstdc++ -static-libgcc) +endif() target_link_libraries(lbugjs PRIVATE lbug ${NODEJS_LBUG_LINK_DEPS} ${CMAKE_JS_LIB})