简体   繁体   English

在Linux环境下构建32位和64位应用程序(C ++)

[英]Linux environment to build 32 and 64-bit application (C++)

I'm looking for advice on how to set up a build machine for a Linux application that needs to be compiled for both 32 and 64-bit architectures. 我正在寻找有关如何为需要针对32位和64位体系结构进行编译的Linux应用程序设置构建机器的建议。

As far as I know, I'll need a 64 bit OS, which can build both 32 and 64. Adding the -m32 flag will produce the right output for 32, no challenge here. 据我所知,我需要一个可以同时构建32和64的64位OS。添加-m32标志将为32提供正确的输出,在这里没有挑战。

The main issue is with libraries. 主要问题是图书馆。 I'm not sure on how to proceed... How can I make sure the linker is using the 32 bit versions of simple libraries, such as ldl, lz, lrt? 我不确定如何继续...如何确定链接器正在使用32位版本的简单库,例如ldl,lz,lrt? I understand I must install the 32 bit versions of all of them, and then configure the linker path. 我了解我必须安装所有版本的32位版本,然后配置链接器路径。

Another issue is the version of the compiler, linker, libc and so on. 另一个问题是编译器,链接器,libc等的版本。 Should I use the oldest versions, in order to ensure all clients will run without issues? 我是否应该使用最旧的版本,以确保所有客户端都能正常运行? I mean, if I build the app in the latest Debian, in older Debians it won't work properly, correct? 我的意思是,如果我在最新的Debian中构建应用程序,则在较旧的Debians中将无法正常工作,对吗?

Thanks for the help! 谢谢您的帮助!

Most versions of Linux that have a 64-bit build also make a 32-bit build and nearly all libraries are available for both, so all you need to do is install the relevant 32-bit libraries in parallel with the 64-bit ones. 大多数具有64位版本的Linux版本也都具有32位版本,并且几乎所有库都可用于这两种版本,因此您所需要做的就是将相关的32位库与64位库并行安装。 The configuration of paths is no different than for a pure 64- or 32-bit build in most cases. 在大多数情况下,路径的配置与纯64位或32位版本相同。 There may be a few libraries that have problems, but you really need to go looking for those. 可能有几个库有问题,但是您确实需要寻找这些库。 All of the mainstream packets will have libraries that work with 32- and 64-bit library versions both installed at the same time. 所有主流数据包都将具有可同时安装32位和64位库版本的库。

When it comes to "which libc", etc, that's a more difficult question, since it will really depend on what your customers have on their machines - and it's unlikely that you can dictate that they should be using one of Debian, RedHat or SuSE - they will feel very strongly about using whatever they are using. 当涉及到“哪个libc”等问题时,这是一个更困难的问题,因为这实际上取决于客户在他们的计算机上拥有什么-您不太可能指示他们应该使用Debian,RedHat或SuSE中的一种-无论使用什么,他们都会感到非常强烈。 Using a "too old" library is just as bad as using a "too new" library. 使用“太旧”的库与使用“太新”的库一样糟糕。 The usual solution to this is to build multiple versions, one for a selected RedHat release (and that should work with a few steps newer/older version, typically, as well as the Fedora versions in the same range), a Debian version, and a SuSE version, maybe one or two more distros. 通常的解决方案是构建多个版本,一个用于选定的RedHat发行版(该版本应与较新/较旧的版本(通常以及同一范围内的Fedora版本)配合使用,仅需几个步骤即可),Debian版本和SuSE版本,也许还有一两个发行版。

And yes, at that point, you probably want to set up a build machine with a few virtual machines on it, so that you don't have to have 3, 5, or 12 physical machines. 是的,到那时,您可能要设置一台构建机,上面有几个虚拟机,这样您就不必拥有3、5或12个物理机。

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

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