如何使用红帽开发人员工具集构建 32 位二进制文件?



我找不到任何关于如何使用红帽开发人员工具集(在本例中为 9.0 版,运行在 CentOS 7 上(面向 32 位的文档。发行说明中提到:

还支持生成和操作 32 位二进制文件

它还在以下位置提供所需的 32 位库:

/opt/rh/devtoolset-9/root/usr/lib/gcc/x86_64-redhat-linux/9/32/

但是,构建失败。尝试构建最小int main() {}程序的示例:

$ scl enable devtoolset-9 'g++ -m32 tst.cpp'
/opt/rh/devtoolset-9/root/usr/libexec/gcc/x86_64-redhat-linux/9/ld: skipping incompatible /opt/rh/devtoolset-9/root/usr/lib/gcc/x86_64-redhat-linux/9/libstdc++_nonshared.a when searching for -lstdc++_nonshared
/opt/rh/devtoolset-9/root/usr/libexec/gcc/x86_64-redhat-linux/9/ld: cannot find -lstdc++_nonshared
collect2: error: ld returned 1 exit status

它找不到的库实际上存在:

/opt/rh/devtoolset-9/root/usr/lib/gcc/x86_64-redhat-linux/9/32/libstdc++_nonshared.a

再多的-L标志也无法修复它(无论如何,这将是错误的解决方案;链接器甚至不应该尝试以-m32模式加载 64 位库。

我在这里错过了什么?

我想你没有注意到/opt/rh/devtoolset-9/root/usr/lib/gcc/x86_64-redhat-linux/9/32/libstdc++_nonshared.a很可能是一个悬而未决的符号链接:

$ file /opt/rh/devtoolset-9/root/usr/lib/gcc/x86_64-redhat-linux/9/32/libstdc++_nonshared.a
/opt/rh/devtoolset-9/root/usr/lib/gcc/x86_64-redhat-linux/9/32/libstdc++_nonshared.a: broken symbolic link to `../../../i686-redhat-linux/9/libstdc++_nonshared.a'
$ 

然而,不幸的是,目标文件/opt/rh/devtoolset-9/root/usr/lib/gcc/i686-redhat-linux/9/libstdc++_nonshared.a不是由任何 CentOS 软件包提供的(但它应该在devtoolset-9-libstdc++-devel.i686中(。因此,这可能是一个特定于 CentOS 的打包错误,因为 RHEA-2019:4134 为红帽企业 Linux 7 提供了有问题的软件包devtoolset-9-libstdc++-devel-9.1.1-2.6.el7.i686.rpm,包括所需的文件(由 RHEL 7 上的yum install /opt/rh/devtoolset-9/root/usr/lib/gcc/i686-redhat-linux/9/libstdc++_nonshared.a明确验证(。

最新更新