强制gcc在64位平台上编译32位程序

发布于 2024-09-14 12:04:09 字数 214 浏览 3 评论 0原文

我有一个专有程序,正在尝试在 64 位系统上使用。

当我启动安装程序时,它工作正常,但在它尝试更新自身并编译一些模块后,它无法加载它们。

我怀疑这是因为它使用 gcc 并且 gcc 尝试为 64 位系统编译它们,因此该程序无法使用这些模块。

有没有什么方法(一些环境变量或类似的东西)来强制 gcc 为 32 位平台做所有事情。 32 位 chroot 可以工作吗?

I've got a proprietary program that I'm trying to use on a 64 bit system.

When I launch the setup it works ok, but after it tries to update itself and compile some modules and it fails to load them.

I'm suspecting it's because it's using gcc and gcc tries to compile them for a 64 bit system and therefore this program cannot use these modules.

Is there any way (some environmental variables or something like that) to force gcc to do everything for a 32 bit platform. Would a 32 bit chroot work?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

沦落红尘 2024-09-21 12:04:09

您需要让 GCC 使用 -m32 标志。

您可以尝试在 $PATH 中编写一个简单的 shell 脚本并将其命名为 gcc(确保不会覆盖原始 gcc,并确保新脚本位于 $PATH< /code>,并且它使用 GCC 的完整路径,

我认为您需要的代码类似于 /bin/gcc -m32 $* ,具体取决于您的 shell($*)。 包含所有参数,尽管它可能是其他东西 - 非常重要!)

You need to make GCC use the -m32 flag.

You could try writing a simple shell script to your $PATH and call it gcc (make sure you don't overwrite the original gcc, and make sure the new script comes earlier in $PATH, and that it uses the full path to GCC.

I think the code you need is just something like /bin/gcc -m32 $* depending on your shell (the $* is there to include all arguments, although it might be something else – very important!)

聊慰 2024-09-21 12:04:09

通过应用 Alan Pearce 的方法,您可能会获得 32 位二进制文​​件,但也可能会出现如下错误:

fatal error: bits/predefs.h: No such file or directory

如果是这种情况并且您有 apt-get,则只需安装 gcc-multilib

sudo apt-get install gcc-multilib 

You may get a 32-bit binary by applying Alan Pearce's method, but you may also get errors as follows:

fatal error: bits/predefs.h: No such file or directory

If this is the case and if you have apt-get, just install gcc-multilib

sudo apt-get install gcc-multilib 
不气馁 2024-09-21 12:04:09

对于直接使用 gcc/g++ 编译的任何代码,您需要在编译命令行中添加 -m32 选项,只需编辑您的Makefile 中的 CFLAGSCXXFLAGSLDFLAGS 变量。

对于您可能使用的任何第三方代码,您必须确保在构建它时将其配置为交叉编译。运行 ./configure --help 并查看哪个选项可用。在大多数情况下,您可以向配置脚本提供 CFLAGSCXXFLAGSLDFLAGS 变量。您可能还需要将 --build--host 添加到配置脚本中,这样您最终会得到类似的内容

./configure CFLAGS=-m32 CXXFLAGS=-m32 LDFLAGS=-m32 --build=x86_64-pc-linux-gnu --host=i686-pc-linux-gnu

如果编译失败,这可能意味着您需要安装一些64 位机器上的 32 位开发包

For any code that you compile directly using gcc/g++, you will need to add -m32 option to the compilation command line, simply edit your CFLAGS, CXXFLAGS and LDFLAGS variables in your Makefile.

For any 3rd party code you might be using you must make sure when you build it to configure it for cross compilation. Run ./configure --help and see which option are available. In most cases you can provide your CFLAGS, CXXFLAGS and LDFLAGS variables to the configure script. You also might need to add --build and --host to the configure script so you end up with something like

./configure CFLAGS=-m32 CXXFLAGS=-m32 LDFLAGS=-m32 --build=x86_64-pc-linux-gnu --host=i686-pc-linux-gnu

If compilation fails this probably means that you need to install some 32 bit development packages on your 64 bit machine

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文