Rus*_*ene 5 c c++ linux glibc clang
我正在尝试从 Ubuntu 20.04 映像使用 Ubuntu 22.04 的 sysroot 进行编译,但遇到了很多麻烦,出现了如下链接器错误:
/usr/bin/ld: ../build_rootfs/x86_64_jammy/lib/x86_64-linux-gnu/libc.so.6: undefined reference to `_dl_audit_symbind_alt@GLIBC_PRIVATE'
/usr/bin/ld: ../build_rootfs/x86_64_jammy/lib/x86_64-linux-gnu/libc.so.6: undefined reference to `_dl_audit_preinit@GLIBC_PRIVATE'
/usr/bin/ld: ../build_rootfs/x86_64_jammy/lib/x86_64-linux-gnu/libc.so.6: undefined reference to `_dl_fatal_printf@GLIBC_PRIVATE'
/usr/bin/ld: ../build_rootfs/x86_64_jammy/lib/x86_64-linux-gnu/libc.so.6: undefined reference to `__nptl_change_stack_perm@GLIBC_PRIVATE'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Run Code Online (Sandbox Code Playgroud)
完全相同的调用在 Ubuntu 22.04 上运行良好,使用完全相同的编译器和完全相同的 sysroot。
这是我的设置:
/usr/bin/ld: ../build_rootfs/x86_64_jammy/lib/x86_64-linux-gnu/libc.so.6: undefined reference to `_dl_audit_symbind_alt@GLIBC_PRIVATE'
/usr/bin/ld: ../build_rootfs/x86_64_jammy/lib/x86_64-linux-gnu/libc.so.6: undefined reference to `_dl_audit_preinit@GLIBC_PRIVATE'
/usr/bin/ld: ../build_rootfs/x86_64_jammy/lib/x86_64-linux-gnu/libc.so.6: undefined reference to `_dl_fatal_printf@GLIBC_PRIVATE'
/usr/bin/ld: ../build_rootfs/x86_64_jammy/lib/x86_64-linux-gnu/libc.so.6: undefined reference to `__nptl_change_stack_perm@GLIBC_PRIVATE'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Run Code Online (Sandbox Code Playgroud)
编译命令:
// test.cpp
int main(){}
Run Code Online (Sandbox Code Playgroud)
使用 multistrap 创建的 sysroot在哪里../build_rootfs/x86_64_jammy(如果相关,我可以共享最小化的 multistrap 配置,但考虑到相同的 sysroot 在 Ubuntu 22.04 中工作正常,sysroot 似乎不是问题。
我尝试过的事情:
值得注意的是,GCC 能够通过传递来编译它-L/usr/lib/x86_64-linux-gnu/9 -L/usr/lib/x86_64-linux-gnu(是的,即使使用 编译--sysroot),但这看起来很奇怪,因为这是链接到主机系统上的库。添加这些标志确实可以让编译成功,但在 22.04 上从 clang 编译可以正常工作,无需加载任何系统库(据称)。
我认为这是 glibc 版本的问题,但我看不出从 sysroot 编译时主机 glibc 版本有何影响,而且似乎任何链接器输入实际上都不是来自主机系统,所以什么是出了问题吗?
这个要点有来自 clang on focus、gcc on focus 和 clang on jammy 的详细日志,以供参考。
最后发现我做错了什么 -$rootfs/lib64/ld-linux-x86-64.so.2是一个符号链接/lib/x86_64-linux-gnu/ld-2.31.so,因此将其修复为相对符号链接而不是绝对符号链接修复了它。
| 归档时间: |
|
| 查看次数: |
832 次 |
| 最近记录: |