57

我使用的是 64 位系统,但想要一组 32 位二进制文​​件。我必须将哪些选项传递给配置脚本以生成 32 位/x86 生成文件?

4

5 回答 5

73

将以下参数传递给配置脚本允许我在 64 位 Linux 上构建 32 位库

./configure --build=i686-pc-linux-gnu CFLAGS=-m32 CXXFLAGS=-m32 LDFLAGS=-m32
于 2010-07-25T04:46:31.060 回答
52

Jack's answer is incomplete.

You need compiler/libc support for 32-bit compilation. In some distros like Ubuntu, what you need to do is install packages gcc-multilib and/or g++-multilib:

sudo apt-get install gcc-multilib g++-multilib

Then you can call configure as you said, specifyiong a 32-bit host and passing 32-bit compilation flags:

./configure --host=i686-linux-gnu "CFLAGS=-m32" "CXXFLAGS=-m32" "LDFLAGS=-m32"

If you do not have multilib installed, you will get an error like configure: error: C compiler cannot create executables when passing the -m32 flag.

于 2013-07-19T14:03:23.887 回答
8

我通过设置自定义编译器获得了更好的成功。这样,所有的配置测试,甚至是使用自定义 CFLAGS 的测试,都能正常工作:

./configure CC="gcc -m32" CXX="g++ -m32"

当然,您仍然需要应用程序使用的所有库的 32 位版本,因此有关缺少库的任何错误都指的是 32 位版本。

于 2015-02-20T22:52:06.103 回答
4

假设 gcc/g++:

CPPFLAGS=-m32 ./configure ...
于 2010-07-16T04:33:24.000 回答
1

上述事情的另一种方法是(如果有的话)使用专用的 x86 编译器。然后配置行将是这样的(我以模式“<toolname>-x86”命名 x86-tools):

CC="/path/to/c/compiler/gcc-x86" CXX="path/to/cpp/compiler/g++-x86" LD="path/to/linker/ld-x86" ./configure
于 2015-07-11T16:07:04.240 回答