Author Topic: How do you compile as 32bit / 64bit program?  (Read 10028 times)

Offline TheSilverHammer

  • Single posting newcomer
  • *
  • Posts: 6
How do you compile as 32bit / 64bit program?
« on: July 07, 2009, 03:50:53 pm »
I am using ubuntu 64 bit with codeblocks 8.02.  My executable is 64 bit which is fine considering I am running 64 bit.  Now I want to compile it as a 32bit application.  I can not find in code blocks where the "--target=x86_64-pc-linux-gnu" is set so I can change it to "--target=i386-pc-linux-gnu".  Where is this option set?

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9592
Re: How do you compile as 32bit / 64bit program?
« Reply #1 on: July 07, 2009, 04:16:52 pm »
Where is this option set?
There are two relevant fields in the build options:
"Other compiler options" on the compiler tab and
"Other linker options" on the linker tab.

In these fields you can add any additional options to any compiler not directly supported via UI.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: http://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: http://wiki.codeblocks.org/index.php?title=FAQ

Offline TheSilverHammer

  • Single posting newcomer
  • *
  • Posts: 6
Re: How do you compile as 32bit / 64bit program?
« Reply #2 on: July 07, 2009, 04:31:28 pm »
Ok, I looked in the build log and there isn't anything being set anywhere.  I guess it defaults.  It seems the option I want is -m32, not the above.  Thanks.

Actually I do not think the -m32 option is the right one.  I can run the -m32 executable on my 64 bit os.  I was told you can't run 32bit executables on a 64 bit ubuntu OS, which would imply this executable will not run on a true 32bit ubuntu installation.

Does anyone know the right flags to make sure the finished binary will run on the right platforms?
« Last Edit: July 07, 2009, 05:08:13 pm by TheSilverHammer »

Offline jens

  • Administrator
  • Lives here!
  • *****
  • Posts: 7253
    • Jens' unofficial debian-repository for the Code::Blocks - IDE
Re: How do you compile as 32bit / 64bit program?
« Reply #3 on: July 07, 2009, 05:39:45 pm »
If you have 32-bit libraries installed it might work.

You can test the file on console with the "file"-command, to see whether it is 32- or 64-bit.

Offline TheSilverHammer

  • Single posting newcomer
  • *
  • Posts: 6
Re: How do you compile as 32bit / 64bit program?
« Reply #4 on: July 07, 2009, 05:50:21 pm »
Ok thanks for that tip.  It comes back: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.15, stripped

I assume it is 32 bit and will run fine on 32-bit Linux distros (mostly).  I noticed it is dynamically linked.  Is that a dangerous thing, as in I will find a lot of problems with people not having libraries I need?  Should I change it to static linking and if so, how do I do that?