Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compile for 32bit with Eclipse

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...

Cheers

like image 472
Basil Avatar asked Aug 15 '10 15:08

Basil


2 Answers

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

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".

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.

like image 159
Basil Avatar answered Oct 08 '22 01:10

Basil


For those looking how to install the libraries mentioned by Basil on Linux (Ubuntu)

$ apt-get install lib32gcc1 libc6-i386 lib32z1 lib32stdc++6

$ apt-get install lib32asound2 lib32ncurses5 lib32gomp1 lib32z1-dev lib32bz2-dev

$ apt-get install g++-multilib

Source: http://sixarm.com/about/ubuntu-apt-get-install-ia32-for-32-bit-on-64-bit.html

like image 29
Olly Avatar answered Oct 07 '22 23:10

Olly