使用交叉编译器时什么时候需要sysroot?

发布于 2025-01-09 01:40:02 字数 617 浏览 5 评论 0原文

我正在使用 Bootlin aarch64 工具链 交叉编译一些 C++ 代码。我注意到我可以很好地编译,只需调用编译器而无需任何特殊标志。具体来说,我可以在不传递 --sysroot 标志的情况下进行编译。我可以看到编译器已配置了 --with-sysroot 选项:

--with-sysroot=/opt/aarch64--glibc--stable-2020.08-1/aarch64-buildroot-linux-gnu/sysroot

但是,我没有将编译器放置在该位置,所以我希望它不知道 sysroot 是什么使用。

我还可以看到它使用的默认系统包含列表,并且相对于编译器的位置,所有路径都已正确计算。因此它将使用工具链中的标头,而不是 /usr/include 等处的标准标头。

因此我的问题是:我需要在这里使用 --sysroot 吗?它能解决什么问题?或者换句话说,如果在这种情况下我不通过该标志,我会遇到什么问题?

I'm using a Bootlin aarch64 toolchain to cross-compile some C++ code. I notice that I can compile just fine simply calling the compiler without any special flags. Specifically, I can compile without passing the --sysroot flag. I can see that the compiler has been configured with the --with-sysroot option:

--with-sysroot=/opt/aarch64--glibc--stable-2020.08-1/aarch64-buildroot-linux-gnu/sysroot

However, I don't have the compiler placed in that location, so I'd expect it to not know what sysroot to use.

I can also see the default system include list that it uses, and all paths are correctly calculated, relative to the location of the compiler. So it will use the headers from the toolchain instead of the standard ones at /usr/include and so on.

Therefore my question is: do I need to use --sysroot here? What problem would it solve? Or put differently - what problems can I run into if I don't pass that flag in this case?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

月亮邮递员 2025-01-16 01:40:02

简而言之,它允许您构建可能需要额外依赖项的项目,但不会造成混乱。

例如,假设您必须在项目中使用 libasdf.so 库。您构建了该库,完成此操作后,您将无法使用它,因为您的项目不知道如何找到它。当然,您可以指定在某个特定路径中查找它,但是如果您有十几个库可供使用怎么办?这会很不方便,并且会造成混乱的标志。

这就是为什么您将这些库安装到 sysroot 中,现在您可以访问系统应该拥有的任何库,就像它安装在主系统上一样。

To put it simple, it's to allow you to build projects that may require additional dependencies, but without creating a mess.

For example, let's say you have to use library libasdf.so in your project. You build that library, after you've done this, you won't be able to use it, since your project doesn't know how to find it. Sure, you can specify to look for it in some specific path, but what if you have a dozen of libraries to use? That would be inconvinient, and create a mess of flags.

That's why you install these libraries into your sysroot, now you can have access to any library your system is supposed to have as if it was installed on your main system.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文