如何与外部库时,交叉编译工作? [英] how to work with external libraries when cross compiling?

查看:330
本文介绍了如何与外部库时,交叉编译工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一些code树莓PI ARM目标86 ubuntu的机器上。我使用的是gcc-Linaro的-armhf工具链。我能交叉编译并运行PI一些独立的程序。现在,我想我的code。与外部库链接,如ncurses的。我怎样才能做到这一点。

I am writing some code for raspberry pi ARM target on x86 ubuntu machine. I am using the gcc-linaro-armhf toolchain. I am able to cross compile and run some independent programs on pi. Now, I want to link my code with external library such as ncurses. How can I achieve this.

如果我只是链接我的程序与主机上现有的ncurses lib和然后在ARM上运行? (我不认为这将工作)
我需要得到lib中手臂来源或prebuilt版本,把它放在我的库路径,然后编译?

Should I just link my program with the existing ncurses lib on host machine and then run on ARM? (I don't think this will work) Do I need to get source or prebuilt version of lib for arm, put it in my lib path and then compile?

什么是这种情况的最佳做法是什么?

What is the best practice in this kind of situation?

我也想知道它是如何工作的C stdlib的。在我的节目我用标准输入输出功能和它交叉编译后的工作没有做什么特别的。我只是在makefile文件我的手臂GCC提供的路径。所以,我想知道,它是如何得到正确的性病头文件和库?

I also want to know how it works for the c stdlib. In my program I used the stdio functions and it worked after cross compiling without doing anything special. I just provided path for my arm gcc in makefile. So, I want to know, how it got correct std headers and libs?

推荐答案

关于你的一般性问题:

为什么C库的作品:

C库是你的十字架工具链的一部分。这就是为什么头被发现和程序正确链接和运行。这也是其他一些非常基本的系统库类似的libm和libstdc ++真(不是在任何情况下,依赖于工具链配置)。

The C library is part of your cross toolchain. That's why the headers are found and the program correctly links and runs. This is also true for some other very basic system libraries like libm and libstdc++ (not in every case, depends on the toolchain configuration).

在与跨平台开发打交道时,一般你需要一些方法来获得所需的库交叉编译。在这种情况下使用的二进制文件是非常罕见的。也就是说,尤其是与ARM硬件,因为有这么多不同的配置,往往一切都剥离下来很多不同的方式。这就是为什么二进制文件不是很二元不同的设备和Linux配置之间的兼容。

In general when dealing with cross-development you need some way to get your desired libraries cross-compiled. Using binaries in this case is very rare. That is, especially with ARM hardware, because there are so many different configurations and often everything is stripped down much in different ways. That's why binaries are not very much binary compatible between different devices and Linux configurations.

如果你在树莓派运行Ubuntu再有就是,你会发现在互联网上或者甚至在一些Ubuntu的APT仓库合适的ncurses库的机会。典型的方式,但是,将穿越你已经拿到了具体的编译工具链库。

If you're running Ubuntu on the Raspberry Pi then there is a chance that you may find a suitable ncurses library on the internet or even in some Ubuntu apt repository. The typical way, however, will be to cross compile the library with the specific toolchain you have got.

在情况下,当大量而复杂的图书馆需要进行交叉编译有解决方案,使生活更轻松,有点像buildroot的或ptxdist。这些方案构建完整的Linux内核和根文件系统的嵌入式设备。

In cases when a lot and complex libraries need to be cross-compiled there are solutions that make life a bit easier like buildroot or ptxdist. These programs build complete Linux kernels and root file systems for embedded devices.

在您的情况,但是,只要你只想要的ncurses你可以编译源$ C ​​$ C自己。你只需要下载源代码,运行配置在使用指定您的工具链 - 主机选项。在 - preFIX 选项将选择安装目录。运行后制作使安装,考虑一切正常,你将已经得到了一组标题和设防的编译的库为您的应用程序进行链接。

In your case, however, as long as you only want ncurses you can compile the source code yourself. You just need to download the sources, run configure while specifying your toolchain using the --host option. The --prefix option will choose the installation directory. After running make and make install, considering everything went fine, you will have got a set of headers and the ARM-compiled library for your application to link against.

对于交叉编译,你一定会找到的在互联网上,也许ncurses的信息负荷已经得到了它的发货文档中的一些指点了。

Regarding cross compilation you will surely find loads of information on the internet and maybe ncurses has got some pointers in its shipped documentation, too.

这篇关于如何与外部库时,交叉编译工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆