tom
tom

Reputation: 1590

Compiling gcc-4.1

Unfortunately I'm forced to use gcc-4.1 and I'm using debian wheezy. Since gcc-4.1 is not in repository I'm trying to build gcc from sources.

But I'm getting compiling error:

/usr/bin/ld: skipping incompatible /usr/lib/x86_64-linux-gnu/libc.so when searching for -lc
/usr/bin/ld: skipping incompatible /usr/lib/x86_64-linux-gnu/libc.a when searching for -lc
/usr/bin/ld: i386:x86-64 architecture of input file `/usr/lib/x86_64-linux-gnu/crti.o' is incompatible with i386 output
/usr/bin/ld: i386:x86-64 architecture of input file `/usr/lib/x86_64-linux-gnu/crtn.o' is incompatible with i386 output

It looks that ld is picking wrong version of libraries, but I checked my /usr/lib32 and /usr/lib/x86_64-linux-gnu/ and it contains those files:

/usr/lib32/libc.a
/usr/lib32/libc.so
/usr/lib32/crtn.o
/usr/lib32/crti.o
/usr/lib/x86_64-linux-gnu/libc.a
/usr/lib/x86_64-linux-gnu/libc.so
/usr/lib/x86_64-linux-gnu/crtn.o
/usr/lib/x86_64-linux-gnu/crti.o

And ld should have access to them

~$ echo $LIBRARY_PATH
/usr/lib/x86_64-linux-gnu:/usr/lib32/

So I have no idea where the problem is.

Upvotes: 1

Views: 1466

Answers (3)

Bahram Alinezhad
Bahram Alinezhad

Reputation: 9

I had this problem recently and finally solved it this way:

ln -s /usr/lib32 /usr/lib/i386-linux-gnu

Notes:

  1. I assumed you do not have /usr/lib/i386-linux-gnu directory in your 64bit linux. If this directory exists and is empty, please delete it and make the above link.

  2. If the directory already exists and is not empty, you have to make links inside it for (32bit) libraries which cause build error one by one; e.g.:
    ln -s /usr/lib32/crti.o /usr/lib/i386-linux-gnu/crti.o
    ln -s /usr/lib32/crtn.o /usr/lib/i386-linux-gnu/crtn.o
    ...

  3. If 32bit development libraries are not installed, you may have to install them first. I've searched different forums and found that installing following set of packages in ubuntu will provide them:

libc6-dev libc6-dev-i386
gcc-multilib g++-multilib
zlib1g-dev lib32z1-dev
libncurses5-dev lib32ncurses5-dev libncursesw5-dev lib32ncursesw5-dev

  1. Also adjust LD_LIBRARY_PATH and LIBRARY_PATH variables so that they contain /usr/lib/i386-linux-gnu and /usr/lib/x86_64-linux-gnu (i.e. multiarch lib-dirs). I am not sure which one of above variables is effective, so I adjust both of them the same.

  2. If you use ./configure --disable-multilib as it is frequently suggested on web, though gcc will be built, but when you want to use that gcc for compiling e.g. legacy grub, you probably get error of "gcc cannot build executable" (or such).

  3. Optionally, you can make similar linking for these pair of libdirs:
    ln -s /lib32 /lib/i386-linux-gnu

Doing so, I managed to compile gcc-3.4.6 in a Ubuntu 16.04.6-amd64 used for compiling old 32bit programs like SDL 1.2 and legacy GRUB4DOS 0.4.4.

Also take a look at my answer to similar (though opposite) error here.

Good luck.

Upvotes: -1

tom
tom

Reputation: 1590

I managed to work around the problem.

Run configure with:

./configure --disable-multilib ...

But than I encountered another problem with makeinfo, if you have newer version >=4.10 than it might not be found by configure. So simple fix in generated makefile worked for me:

Change this line:

MAKEINFO = /home/lecopivo/Downloads/gcc412/gcc412/gcc-4.1.2/missing makeinfo

To this:

MAKEINFO = makeinfo

I found this helpful.

Upvotes: 4

ams
ams

Reputation: 25569

LD_LIBRARY_PATH is only for running programs already linked.

You probably need to set LDFLAGS when you configure gcc:

./configure LDFLAGS="-L/usr/lib32" .....

It might be LDFLAGS_FOR_HOST or LIBS or something like that though.

Upvotes: 0

Related Questions