简体   繁体   English

musl 的 GCC 包装器与 musl 的交叉编译器有何不同?

[英]How does musl's GCC wrapper differ from musl's cross-compiler?

I am trying to compile various programs such as MariaDB with a musl toolchain.我正在尝试使用musl工具链编译各种程序,例如 MariaDB。 That is, I don't want any dependencies on glibc or GNU's linker after compilation has finished.也就是说,我不希望在编译完成后对 glibc 或 GNU 的链接器有任何依赖。

Thus far, I have been using musl's GCC wrapper, musl-gcc to compile things.到目前为止,我一直在使用 musl 的 GCC 包装器musl-gcc来编译东西。 But, with larger programs like MariaDB I struggle to get all the necessary libraries and headers and symlinking or adding environment variables for the compilation doesn't really help .但是,对于像 MariaDB 这样的大型程序,我很难获得所有必要的库和头文件,并且符号链接或为编译添加环境变量并没有真正的帮助

I see mention of building a cross-compiler targeting musl libc with additional documentation and code at this GitHub repo .我在此 GitHub repo 上看到提到构建一个针对 musl libc 的交叉编译器,并附有其他文档和代码。 From the documentation on the cross-compiler:从交叉编译器的文档中:

This gives you a full, relocatable musl-targeting toolchain, with C++ support and its own library paths you can install third-party libraries into.这为您提供了一个完整的、可重定位的 musl 目标工具链,具有 C++ 支持和它自己的库路径,您可以将第三方库安装到其中。

It sounds like this could help me, but I am not sure how this is very different from musl's GCC wrapper, which as I understand, just alters where GCC looks for libraries and headers etc.听起来这可以帮助我,但我不确定这与 musl 的 GCC 包装器有什么不同,据我了解,它只是改变了 GCC 查找库和头文件等的位置。

Ultimately, I am unsure how different this cross-compiler really is from the GCC wrapper and if it would be useful in my case.最终,我不确定这个交叉编译器与 GCC 包装器到底有多大不同,以及它是否对我有用。 Why would I need my own library paths to install third-party libraries into when I can just symlink to existing libraries and use the GCC wrapper?当我可以符号链接到现有库并使用 GCC 包装器时,为什么我需要自己的库路径来安装第三方库? Is the cross-compiler the way I should be compiling things, especially bigger code bases?交叉编译器是我应该编译的方式吗,尤其是更大的代码库?

All the wrapper does is remove the default library and include paths and add replacement ones.包装器所做的就是删除默认库并包含路径并添加替换路径。 Otherwise, it relies on the compiler's view of the ABI being sufficiently matched that a GCC that thinks it's targeting glibc ( *-linux-gnu ) works with a musl ( *-linux-musl ) target.否则,它依赖于编译器对 ABI的看法是否足够匹配,以至于认为它的目标是 glibc ( *-linux-gnu ) 的 GCC 与 musl ( *-linux-musl ) 目标一起工作。

A full GCC toolchain has a number of "target libraries" - libraries that are linked into the output program to provide some functionality the compiler offers.一个完整的 GCC 工具链有许多“目标库”——这些库链接到输出程序中以提供编译器提供的一些功能。 This includes libgcc (software multiply or divide, software floating point, etc. according to whether the target arch needs these things, and unwinding support for exception handling), libstd++ (the C++ standard library), and a number of other things like libgomp (GNU OpenMP runtime implementation for use with #pragma OMP ... ).这包括libgcc (软件乘法或除法、软件浮点数等,根据目标 arch 是否需要这些东西,以及对异常处理的展开支持)、 libstd++ (C++ 标准库)和许多其他东西,如libgomp ( GNU OpenMP 运行时实现,用于#pragma OMP ... )。 In theory all of these possibly depend on the specific target ABI, including the libc, and potentially link to symbols from libc.理论上,所有这些都可能取决于特定的目标 ABI,包括 libc,并可能链接到来自 libc 的符号。 In practice, for the most part libgcc doesn't, and is "safely" reusable with a different libc as long as the basic type definitions and a few other ABI things match.实际上,在大多数情况下, libgcc不会,并且只要基本类型定义和其他一些 ABI 内容匹配,就可以“安全地”使用不同的 libc 重用。

For the other libraries with more complex dependencies on libc, it's generally not expected that a build against one libc would work with a different one.对于对 libc 具有更复杂依赖关系的其他库,通常不会预期针对一个 libc 的构建会与不同的 libc 一起使用。 musl libc provides some degree of ABI-compat for using glibc-linked libraries, so there's some hope that they'd work anyway, but you'd need to copy them to the new library path. musl libc 为使用 glibc 链接的库提供了一定程度的 ABI 兼容性,因此希望它们无论如何都能工作,但您需要将它们复制到新的库路径。 However, GCC's C++ standard library headers also seem to have some heavy dependency on the (libc) system headers for the target, and when setup for glibc do not seem to work with musl.但是,GCC 的 C++ 标准库头文件似乎也严重依赖于目标的 (libc) 系统头文件,并且当 glibc 设置似乎不适用于 musl。 There is probably some way to make this work (ie to add C++ support to the wrapper), but it's an open problem exactly how to do it.可能有一些方法可以使这项工作(即向包装器添加 C++ 支持),但究竟如何做到这一点是一个悬而未决的问题。

Even if this could be made to work, though, the deeper you go, the more reasons you're likely to find that you'd rather just have a proper cross-compiler toolchain that knows it's targeting musl.然而,即使这可以奏效,你越深入,你就越有可能发现你宁愿拥有一个知道它针对 musl 的适当的交叉编译器工具链。 And nowadays these are easy enough to build.如今,这些很容易构建。 But if you find you're needing additonal third party libraries too, and don't want to build them yourself, it probably makes more sense to just use a Docker image (or other container) with a distro that provides library binaries for you.但是,如果您发现自己也需要额外的第三方库,并且不想自己构建它们,那么使用带有为您提供库二进制文件的发行版的 Docker 映像(或其他容器)可能更有意义。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM