如何使用 Eclipse 编译 32 位
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3488108/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to compile for 32bit with Eclipse
提问by Basil
I'm currently writing a little program in c++ on my 64bit Ubuntu Pc. By default eclipse compiles the program for a 64bit architecture. Since I want to use my little program on my server which is still 32bit, I need to be able to compile my program for 32bit. How could can I do that in eclipse? I've been fiddling for a while with the settings but nothing worked...
我目前正在我的 64 位 Ubuntu Pc 上用 C++ 编写一个小程序。默认情况下,eclipse 为 64 位体系结构编译程序。由于我想在仍然是 32 位的服务器上使用我的小程序,因此我需要能够为 32 位编译我的程序。我怎么能在日食中做到这一点?我一直在摆弄设置,但没有任何效果......
Cheers
干杯
回答by Basil
I found the answer myself, after lots of searching and trying things out. This is a solution that works if you happen to have the same problem. For this to work the following packages have to be installed:
经过大量搜索和尝试,我自己找到了答案。如果您碰巧遇到同样的问题,这是一个有效的解决方案。为此,必须安装以下软件包:
gcc/g++ with multilib
ia32-libs
带有 multilib 的 gcc/g++
ia32-libs
Then right click on your project, and select "properties". Go to "C/C++ Build" and choose "settings". Under "GCC/G++ Compiler" add "-m32" to the command field (the field should now say "g++ -m32"). Do the same for "GCC/G++ Linker".
然后右键单击您的项目,并选择“属性”。转到“C/C++ Build”并选择“设置”。在“GCC/G++ Compiler”下的命令字段中添加“-m32”(该字段现在应该显示为“g++ -m32”)。对“GCC/G++ 链接器”执行相同操作。
Now that you have added the flag, this should be compiled for 32bit. I'm using Eclipse Galileo, for the case that your interface looks different. I only added the "-m32" flag only under the "Release" profile, so my "Debug" builds are still 64bit.
现在您已经添加了标志,这应该被编译为 32 位。我正在使用 Eclipse Galileo,因为您的界面看起来不同。我只在“发布”配置文件下添加了“-m32”标志,所以我的“调试”版本仍然是 64 位。
回答by Olly
For those looking how to install the libraries mentioned by Basil on Linux (Ubuntu)
对于那些寻找如何在 Linux (Ubuntu) 上安装 Basil 提到的库的人
$ apt-get install lib32gcc1 libc6-i386 lib32z1 lib32stdc++6
$ apt-get install lib32gcc1 libc6-i386 lib32z1 lib32stdc++6
$ apt-get install lib32asound2 lib32ncurses5 lib32gomp1 lib32z1-dev lib32bz2-dev
$ apt-get install lib32asound2 lib32ncurses5 lib32gomp1 lib32z1-dev lib32bz2-dev
$ apt-get install g++-multilib
$ apt-get install g++-multilib
Source: http://sixarm.com/about/ubuntu-apt-get-install-ia32-for-32-bit-on-64-bit.html
来源:http: //sixarm.com/about/ubuntu-apt-get-install-ia32-for-32-bit-on-64-bit.html