Pun*_*oni 30 c linux gcc arm cross-compiling
我在x86 ubuntu机器上为raspberry pi ARM目标编写了一些代码.我正在使用gcc-linaro-armhf工具链.我能够在pi上交叉编译并运行一些独立的程序.现在,我想将我的代码链接到外部库,如ncurses.我怎样才能做到这一点.
我应该将我的程序与主机上现有的ncurses lib链接,然后在ARM上运行吗?(我认为这不会起作用)我是否需要为arm获取lib的源代码或预构建版本,将其放入我的lib路径然后编译?
在这种情况下,最佳做法是什么?
我也想知道它如何用于c stdlib.在我的程序中,我使用了stdio函数,它在交叉编译后工作,没有做任何特殊的事情.我刚刚在makefile中为我的arm gcc提供了路径.所以,我想知道,它是如何得到正确的标准头文件和库?
ger*_*tra 25
关于你的一般问题:
为什么C库有效:
C库是交叉工具链的一部分.这就是找到标题并且程序正确链接和运行的原因.对于其他一些非常基本的系统库(如libm和libstdc ++)也是如此(并非在每种情况下都依赖于工具链配置).
通常,在处理交叉开发时,您需要一些方法来交叉编译所需的库.在这种情况下使用二进制文件是非常罕见的.也就是说,特别是对于ARM硬件,因为有许多不同的配置,并且通常所有内容都以不同的方式被剥离.这就是为什么二进制文件在不同设备和Linux配置之间不是很多二进制兼容的原因.
如果您在Raspberry Pi上运行Ubuntu,那么您可能会在Internet上甚至在某些Ubuntu apt存储库中找到合适的ncurses库.然而,典型的方法是使用您拥有的特定工具链交叉编译库.
在需要交叉编译大量复杂库的情况下,有一些解决方案可以让生活变得像buildroot或ptxdist一样简单.这些程序为嵌入式设备构建完整的Linux内核和根文件系统.
但是,在您的情况下,只要您只想要ncurses,您就可以自己编译源代码.您只需下载源代码,configure在使用该--host选项指定工具链时运行.该--prefix选项将选择安装目录.运行后make,并make install考虑一切正常,你会得到一个套头,并为您的应用程序来链接的ARM编译库.
关于交叉编译,您肯定会在互联网上找到大量信息,也许ncurses也在其发布的文档中有一些指示.
vin*_*yal 16
对于查询 How the C library works in cross-tools
在配置期间编译和构建跨工具链时,它们将提供sysroot.
喜欢 --with-sysroot=${CLFS_CROSS_TOOLS}
--with-sysroot
--with-sysroot=dir
Tells GCC to consider dir as the root of a tree that contains (a subset of) the root filesystem of the target operating system. Target system headers, libraries and run-time object files will be searched for in there. More specifically, this acts as if --sysroot=dir was added to the default options of the built compiler. The specified directory is not copied into the install tree, unlike the options --with-headers and --with-libs that this option obsoletes. The default value, in case --with-sysroot is not given an argument, is ${gcc_tooldir}/sys-root. If the specified directory is a subdirectory of ${exec_prefix}, then it will be found relative to the GCC binaries if the installation tree is moved.
因此,在/lib /usr/include编译时,它不会看起来像/ Toolchain /(libc)和(包含文件)
你可以检查一下
arm-linux-gnueabihf-gcc -print-sysroot
这个节目在哪里寻找libc.
也
arm-linux-gnueabihf-gcc -print-search-dirs
给你清晰的图片