Force gcc to compile 32 bit programs on 64 bit platform

后端 未结 3 1635
死守一世寂寞
死守一世寂寞 2020-12-04 13:24

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 som

相关标签:
3条回答
  • 2020-12-04 13:50

    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 
    
    0 讨论(0)
  • 2020-12-04 13:53

    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!)

    0 讨论(0)
  • 2020-12-04 13:54

    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

    0 讨论(0)
提交回复
热议问题