简体   繁体   English

交叉编译:检查是否可以在64位计算机上构建32位

[英]cross compile: check if it is possible to build 32 bit on a 64 bit machine

While building a C++ project, we have serveral targets: 32 and 64 bits. 在构建C ++项目时,我们有服务器目标:32位和64位。

On some 64 bit machines, while building 32 bit target we are getting a failures because g++-multilib is missing: 在某些64位计算机上,在构建32位目标时,由于缺少g ++-multilib而导致失败:

/usr/include/features.h:374:25: fatal error: sys/cdefs.h: No such file or directory 

My question is this: 我的问题是这样的:

What is the best way to query if the current machine is able to generate a 32 bit image, in terms of compiler and glibc packages installed. 就安装的编译器和glibc软件包而言,查询当前计算机是否能够生成32位映像的最佳方法是什么。

One solution could be, for example, generating a simple C file that contains multiple glibc includes and see if I am able to compile the mock file. 一种解决方案是,例如,生成一个包含多个glibc include的简单C文件,然后查看我是否能够编译该模拟文件。

This does not seem the elegant solution. 这似乎不是一个很好的解决方案。

Instead, I would like to query the machine to see if all the nesscary packages are installed. 相反,我想查询机器以查看是否已安装所有nesscary软件包。

PS: PS:

We are using WAF as a build infrastructure. 我们正在使用WAF作为构建基础结构。

Thanks, 谢谢,

Itay 伊泰

checking for the existence of a given package is usually not a good idea, as it relies on specific distributions (eg Fedora) and specific package names (eg libc6-dev-i386 ); 检查给定软件包的存在通常不是一个好主意,因为它依赖于特定的发行版(例如Fedora)和特定的软件包名称(例如libc6-dev-i386 ); other distributions (or other versions of the same distributions) will have different package names and tools to interact with the package manager (eg apt vs rpm vs ...) 其他发行版(或相同发行版的其他版本)将具有不同的软件包名称和与软件包管理器进行交互的工具(例如apt vs rpm vs ...)

the well-established autotools way is to run tests for the things that you actually need (eg include a given header file) rather than check for things that might provide the things you need (eg a certain package)- 完善的自动工具方法是针对您实际需要的东西(例如,包括给定的头文件)运行测试,而不是检查可能提供您所需的东西(例如某个程序包)-

eg if your actual code requires to include features.h , then you should test (in a pre-build step) whether it is possible to include this file without errors. 例如,如果您的实际代码需要包含features.h ,那么您应该测试(在预构建步骤中)是否可以无错误地包含此文件。

the following autotools example will stop with an error if features.h cannot be used; 如果无法使用features.h则以下自动工具示例将因错误而停止; which allows the user to fix the problem by installing the correct packages (eg as hinted in your README) before starting a time-consuming build process. 这使用户可以在开始耗时的构建过程之前通过安装正确的软件包(例如,自述文件中提示)来解决问题。

 #snippet from configure.ac
 #stop configure process if we cannot use foo.h
 AC_CHECK_HEADERS([foo.h],,AC_ERROR([cannot include foo.h - try installing libfoo-dev])

if instead of failing the configure step you would rather simply disable parts of your build, you might want to do something like this: 如果不想让配置步骤失败,而只是简单地禁用构建的某些部分,则可能需要执行以下操作:

configure.ac: configure.ac:

 have_bar_h="no"
 AC_CHECK_HEADERS([bar.h],[have_bar_h="yes"])
 AM_CONDITIONAL([BAR]) [ test "x${have_bar_h}" = "yes" ]

and Makefile.am 和Makefile.am

 if BAR
 # only do the 32bit build if we have bar.h
 bin_PROGRAMS+=coolapp32
 ebduf

sorry that this answer is very autotools specific, but i'm sure that waf has similar ways; 抱歉,这个答案是非常特定于autotools的,但是我确定waf具有类似的方式; check the section about Configuration helpers in the WAF documentation . 检查WAF文档中有关配置帮助器的部分。

It might help, 这可能会有所帮助,

try to install libc6-dev-i386 on your machine which is Embedded GNU C Library: 32-bit development libraries for AMD64. 尝试在您的嵌入式GNU C库机器上安装libc6-dev-i386 :用于AMD64的32位开发库。

您想查询机器以查看是否已安装所有必需的32位软件包...

rpm -qa --queryformat 'libc6-dev-%{ARCH}\n' | grep 'i[6543]86' | cut -d' ' -f1

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

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