rohitsan
rohitsan

Reputation: 1041

How to build a gcc compiler on Linux that builds both 32-bit and 64-bit code

I followed the directions in the following URL to build a gcc compiler for Linux:

https://solarianprogrammer.com/2016/10/07/building-gcc-ubuntu-linux/

The resulting compiler builds 64-bit code with no problems.

However, when I try to build 32-bit code (by specifying the -m32 compiler option), I get errors.

Here are the errors that I get:

  1. cannot find -lstdc++
  2. cannot find -lgcc_s
  3. skipping incompatible libgcc.a when searching foor -lgcc
  4. cannot find -lgcc

Obviously, when I built the compiler, I did something wrong - can anyone tell me what I did wrong and how I can rebuild the compiler to build both 32-bit and 64-bit code.

Upvotes: 1

Views: 2371

Answers (1)

Chris Dodd
Chris Dodd

Reputation: 126110

You at least need to configure with --with-multilib-list=m32,m64 on the configure command line.1 You definitely need to not configure with --disable-multilib. You may also need to build&install additional versions of other libraries.

In general, searching the documentation for 'multilib' will show you all the places where it talks about building or using gcc with multiple target ABIs.


1This is the default on at least some versions of gcc. You could also add mx32 if you want to experiment with that.

Upvotes: 5

Related Questions