@@ -137,12 +137,28 @@ for stub in "${PARCAGPU_DIR}"/libcupti.so*; do
137137done
138138
139139# Copy libstdc++ into the RUNPATH so the dynamic linker finds it.
140- # Cross-arch debootstrap doesn't run ldconfig, leaving ld.so.cache incomplete,
141- # so multiarch paths like /usr/lib/aarch64-linux-gnu/ aren't searched.
142- LIBSTDCXX=$( find " $ROOTFS_DIR " -name ' libstdc++.so.6*' -type f | head -1)
143- if [ -n " $LIBSTDCXX " ]; then
144- cp " $LIBSTDCXX " " $ROOTFS_DIR /usr/local/cuda/lib64/"
145- echo " Copied $( basename " $LIBSTDCXX " ) to RUNPATH"
140+ # With --foreign debootstrap the .deb is downloaded but not extracted, so we
141+ # pull the .so directly from the .deb archive.
142+ LIBSTDCXX_DEB=$( find " $ROOTFS_DIR " -name ' libstdc++6_*.deb' -type f | head -1)
143+ if [ -n " $LIBSTDCXX_DEB " ]; then
144+ EXTRACT_TMP=$( mktemp -d)
145+ dpkg-deb -x " $LIBSTDCXX_DEB " " $EXTRACT_TMP "
146+ # Copy the real .so file (not the symlink) and create the soname symlink.
147+ LIBSTDCXX_REAL=$( find " $EXTRACT_TMP " -name ' libstdc++.so.6.*' ! -name ' *.py' -type f | head -1)
148+ if [ -n " $LIBSTDCXX_REAL " ]; then
149+ cp " $LIBSTDCXX_REAL " " $ROOTFS_DIR /usr/local/cuda/lib64/"
150+ ln -sf " $( basename " $LIBSTDCXX_REAL " ) " " $ROOTFS_DIR /usr/local/cuda/lib64/libstdc++.so.6"
151+ echo " Copied $( basename " $LIBSTDCXX_REAL " ) + symlink to RUNPATH from deb"
152+ fi
153+ rm -rf " $EXTRACT_TMP "
154+ else
155+ # Fallback: check if already extracted (non-foreign debootstrap)
156+ LIBSTDCXX_REAL=$( find " $ROOTFS_DIR " -name ' libstdc++.so.6.*' ! -name ' *.py' -type f | head -1)
157+ if [ -n " $LIBSTDCXX_REAL " ]; then
158+ cp " $LIBSTDCXX_REAL " " $ROOTFS_DIR /usr/local/cuda/lib64/"
159+ ln -sf " $( basename " $LIBSTDCXX_REAL " ) " " $ROOTFS_DIR /usr/local/cuda/lib64/libstdc++.so.6"
160+ echo " Copied $( basename " $LIBSTDCXX_REAL " ) + symlink to RUNPATH"
161+ fi
146162fi
147163
148164# List dynamic dependencies for debugging
0 commit comments