How to compile glibc 32bit on an x86_64 machine

前端 未结 3 908
一整个雨季
一整个雨季 2020-12-14 17:52

I\'m trying to compile glibc (as a secondary, not a system replacement) 2.6 on an x86_64, and trying to get it to produce 32-bit objects. When I give it a standard configure

相关标签:
3条回答
  • 2020-12-14 18:22

    The following works for me:

    ../../src/glibc-2.6/configure --prefix=$HOME/glibc32-2.6 \
     CC="gcc -m32" CXX="g++ -m32" i686-linux-gnu
    
    0 讨论(0)
  • 2020-12-14 18:26

    Three important ./configure flags:

    • --build= The system performing the build. Looks like yours is x86_64-pc-linux-gnu.
    • --host= The system on which the generated objects will be used. You want to set this to i386-pc-linux-gnu.
    • --target= If you are building a compiler, the system for which the built compiler will generate objects.

    To perform a cross-compile, you must specify both --build= and --host=. When you only specify --host=, it will still attempt to build a native (x86_64) glibc.

    0 讨论(0)
  • 2020-12-14 18:34

    I edited the question, but then I realized the proper way is to add an answer. Here's what finally worked:

     $ ../../src/glibc-2.6/configure --prefix=$HOME/glibc32-2.6 \
         --host=i686-linux-gnu \
         --build=i686-linux-gnu \
         CC="gcc -m32" CXX="g++ -m32" \
         CFLAGS="-O2 -march=i686" \
         CXXFLAGS="-O2 -march=i686"
    

    I think putting -m32 in CC and CXX instead of CFLAGS and CXXFLAGS was important because there was at least one compile operation during the make which didn't use CFLAGS or CXXFLAGS, and -m32 absolutely has to always be there. Not sure why -march=i686 was necessary (given the -m32 parts and the --host/build options), but it was.

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