【问题标题】:How to compile and install a 32Bit library on a 64 Bit (Ubuntu 12.04LTS) Linux using autotools, make and gcc?如何使用 autotools、make 和 gcc 在 64 位(Ubuntu 12.04LTS)Linux 上编译和安装 32 位库?
【发布时间】:2014-05-31 15:06:31
【问题描述】:

我正在尝试在虚拟机(VirtualBox)内运行的 64 位 Ubuntu 12.04LTS 上编译 32 位版本的 linux 库。

到目前为止,我已经下载了源代码,解压缩并执行了以下步骤来构建库:

libtoolize --force
automake --add-missing
./configure --build=i686-pc-linux-gnu "CFLAGS=-m32" "CXXFLAGS=-m32" "LDFLAGS=-m32"
make
sudo make install

有了这个,我已经能够构建一个编译库,但是,一旦我在编译的库上运行“readelf -h”,我会得到以下输出:

  ELF Header:
  Magic:   7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00 
  Class:                             ELF64
  Data:                              2's complement, little endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - System V
  ABI Version:                       0
  Type:                              DYN (Shared object file)
  Machine:                           Advanced Micro Devices X86-64
  Version:                           0x1
  Entry point address:               0x1ac0
  Start of program headers:          64 (bytes into file)
  Start of section headers:          53904 (bytes into file)
  Flags:                             0x0
  Size of this header:               64 (bytes)
  Size of program headers:           56 (bytes)
  Number of program headers:         7
  Size of section headers:           64 (bytes)
  Number of section headers:         35
  Section header string table index: 32

所以我坚持使用 64 位版本的库,还没有找到强制构建和安装 32 位版本的方法。对于如何解决此问题的提示,我将不胜感激。

【问题讨论】:

    标签: linux ubuntu gcc makefile autotools


    【解决方案1】:

    您只在./configure 的选项中设置--build。这意味着./configure 应该表现得好像程序是在 32 位计算机上编译的。如果您还希望它在 32 位计算机上运行,​​您应该使用--host=i386-linux-gnu。所以你要运行的真正配置命令是:

    ./configure --build=i386-linux-gnu --host=i386-linux-gnu
    

    【讨论】:

    • 感谢随机提示,您提供的命令没有起到作用,但让我走上了正轨。 config.guess 在 VM 中输出“x86_64-unknown-linux-gnu”并再次生成 64 位库。跳过 CF、CXX、LD 标志会导致链接器错误。所以生成 32 位库的正确命令是: ./configure --build=i386-linux-gnu --host=i386-linux-gnu "CFLAGS=-m32" "CXXFLAGS=-m32" "LDFLAGS=-m32" If您相应地编辑您的帖子,我会将其标记为正确答案。
    • @norritt 好吧,我想这回答了这个难题。为自己找出答案做得很好!
    猜你喜欢
    • 2015-09-14
    • 2013-10-23
    • 2014-07-21
    • 2014-01-20
    • 1970-01-01
    • 2014-03-14
    • 2012-03-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多