gpt4 book ai didi

在 Linux 上交叉构建第三方库位置

转载 作者:太空宇宙 更新时间:2023-11-04 11:00:26 25 4
gpt4 key购买 nike

我一直在交叉编译我的单元测试以确保它们在所有感兴趣的平台上通过,例如x86-linux, win32, win64, arm-linux

他们的单元测试需要 CUnit 库

所以我还必须为每个平台交叉编译

它带有自己的 autoconf 东西,因此您可以通过为配置指定 --host 轻松地交叉构建它

我的问题是,为各种平台安装 CUnit 库的“正确”位置在哪里?即我应该为配置设置 --prefix 什么?

我最初的猜测是:

/usr/local/<platform>/lib/Cunit

即设置 --prefix /usr/local/<platform>

例如--prefix /usr/local/arm-linux-gnueabihf

sudo make install 上给你:

/usr/local/arm-linux-gnueabihf/doc/CUnit
/usr/local/arm-linux-gnueabihf/include/CUnit
/usr/local/arm-linux-gnueabihf/lib
/usr/local/arm-linux-gnueabihf/share/CUnit

显然,如果我不为配置指定前缀,每个平台构建都会覆盖前一个,这是不好的

为了成功链接到这些特定于平台的库,我需要在 Makefile 中为每个目标在其自己的 LDFLAGS 中指定相关的库目录

这是正确的方法吗?我的目录结构/位置是否适合这种交叉构建的东西?我假设必须有一个事实上的方法,但不确定它是什么..

可能配置应该为我处理所有这些东西?也许我只需要设置 --target正确,也许 --enable-multilib ?所有与--prefix=/usr/local

我收到的一些错误消息建议 /usr/lib/gcc-cross可能涉及?

通过阅读更多关于交叉编译和 Gnu 配置和构建系统的信息,我似乎应该为配置步骤设置 --target 选项

但是你怎么知道目标名称是什么?它们是交叉编译器名称的一部分吗?

我使用的 3 个交叉编译器是:

arm-linux-gnueabihf-gcc-4.8i686-w64-mingw32-gccx86_64-w64-mingw32-gcc

允许我为 ARM、win32 和 win64 交叉编译

我的主机是 32 位 ubuntu,我认为它可能是 --host i386-linux,但似乎配置应该将其设置为默认值

最佳答案

这是我最终想出并开始工作的程序:

对于我的 3 个交叉构建工具(arm、win32、win64),我对配置的调用如下所示:

./configure --host=arm-linux-gnueabihf --build=i686-pc-linux-gnu --prefix=/usr/local/arm-linux-gnueabihf
./configure --host=i686-w64-mingw32 --build=i686-pc-linux-gnu --prefix=/usr/local/i686-w64-mingw32
./configure --host=x86_64-w64-mingw32 --build=i686-pc-linux-gnu --prefix=/usr/local/x86_64-w64-mingw32

每一个后面都有makesudo make install

在为 arm cross 构建调用配置之前,我必须做:

ln -s /usr/bin/arm-linux-gnueabihf-gcc-4.8 /usr/bin/arm-linux-gnueabihf-gcc

这是因为编译器的末尾有 -4.8 标记,所以 configure 无法正确“猜测”编译器的名称

这个问题不适用于 win32 或 win64 mingw 编译器

注意一个额外的问题是,当随后尝试链接到这些交叉编译的 CUnit 库时,默认情况下似乎没有一个交叉编译器在/usr/local/include 中查找,所以我不得不手动添加:

-I/usr/local/include 

为每个目标文件构建

例如我将 /usr/local/include 添加到我的 Makefile 中的 INCLUDE_DIRS

所有这一切似乎最终为我提供了正确的交叉构建的 CUnit 库,并且我已经成功地链接到它们,为每个目标平台生成交叉构建的单元测试二进制文件。

一点都不容易,我敢说配置选项设置“违反直觉”——因为花时间阅读相关文档是值得的——这个片段是相关的:

There are three system names that the build knows about: the machine you are building on (build), the machine that you are building for (host), and the machine that GCC will produce code for (target). When you configure GCC, you specify these with --build=, --host=, and --target=.

Specifying the host without specifying the build should be avoided, as configure may (and once did) assume that the host you specify is also the build, which may not be true.

If build, host, and target are all the same, this is called a native. If build and host are the same but target is different, this is called a cross. If build, host, and target are all different this is called a canadian (for obscure reasons dealing with Canada's political party and the background of the person working on the build at that time). If host and target are the same, but build is different, you are using a cross-compiler to build a native for a different system. Some people call this a host-x-host, crossed native, or cross-built native.

还有:

When people configure a project like './configure', man often meets these three confusing options, which are more related with cross-compilation

--host: In which system the generated program will run.

--build: In which system the program will be built.

--target: this option is only used to build a cross-compiling
toolchain. When the tool chain generates executable program, in which target
system the program will run.

An example of tslib (a mouse driver library)

'./configure --host=arm-linux --build=i686-pc-linux-gnu': the dynamically library is built on a x86 linux computer but will be used for a embedded arm linux system.

关于在 Linux 上交叉构建第三方库位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27188116/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com