Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

On Monday I've upgraded to from Ubuntu 11.04 (my initial installation) to 11.10 and now I can't build gcc from source anymore. Since I forgot to uninstall the gcc package before the upgrade, Ubuntu replaced my 4.7.0 compiler with it's stable 4.6.1. So I tried to build the SVN sources again, but it fails. I've most recently tried it with SVN revision 180193.

After some time, the build fails with the following message:

/home/raphael/devel/gcc/build/./gcc/xgcc -B/home/raphael/devel/gcc/build/./gcc/ -B/usr/i686-pc-linux-gnu/bin/ -B/usr/i686-pc-linux-gnu/lib/ -isystem /usr/i686-pc-linux-gnu/include -isystem /usr/i686-pc-linux-gnu/sys-include    -g -O2 -O2  -I. -I. -I../../src/gcc -I../../src/gcc/. -I../../src/gcc/../include -I../../src/gcc/../libdecnumber -I../../src/gcc/../libdecnumber/bid -I../libdecnumber -I../../src/gcc/../libgcc -g -O2 -DIN_GCC   -W -Wall -Wwrite-strings -Wcast-qual -Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition  -isystem ./include  -fPIC -g -DHAVE_GTHR_DEFAULT -DIN_LIBGCC2 -fbuilding-libgcc -fno-stack-protector   -I. -I. -I../.././gcc -I../../../src/libgcc -I../../../src/libgcc/. -I../../../src/libgcc/../gcc -I../../../src/libgcc/../include -I../../../src/libgcc/config/libbid -DENABLE_DECIMAL_BID_FORMAT -DHAVE_CC_TLS  -DUSE_TLS -o _ashldi3.o -MT _ashldi3.o -MD -MP -MF _ashldi3.dep -DL_ashldi3 -c ../../../src/libgcc/../gcc/libgcc2.c \
    -fvisibility=hidden -DHIDE_EXPORTS
In file included from /usr/include/stdio.h:28:0,
             from ../../../src/libgcc/../gcc/tsystem.h:88,
             from ../../../src/libgcc/../gcc/libgcc2.c:29:
/usr/include/features.h:323:26: fatal error: bits/predefs.h: File or directory not found.

I've cofigured it with:

~/devel/gcc/build$ ../src/configure --prefix=/usr --enable-languages=c++

And make it with:

~/devel/gcc/build$ make -j4

Just to be sure, I did a rm -rf * in the build directory in case there's some broken stuff inside. Didn't help, though.


That's the backstory. I tried to fix it and searched for the bits/predefs.h. It's inside /usr/include/i386-linux-gnu. I temporarily fixed the problem by doing

~/devel/gcc/build$ C_INCLUDE_PATH=/usr/include/i386-linux-gnu make -j4

Which is only temporary because now gcc complains that it can't find crti.o.

Which i can find in /usr/lib/i386-linux-gnu. Now i could also set C_LIBRARY_PATH - actually it doesn't work - but I feel like I'm fighting the system here. Also, even if it succeeds, my newly built compiler would also not know about the i386-linux-gnu stuff. So I would have to set C_LIBRARY_PATH and C_INCLUDE_PATH before every build of every project I have. I could add it to my .bashrc but that subverts the system even more.

So, how do I tell the build process:

  • That there are additional include/lib directories, and
  • That it should build a gcc which respects them too?

Edit: I forgot to include the command which causes the above error message. Also I can think of another solution: Copy the stuff from /usr/include/i386-linux-gnu to /usr/include (same thing for /usr/lib/i386-linux-gnu to /usr/lib). But that doesn't feel right, either. Finally, the system's gcc 4.6.1 can compile other applications just fine, except mine, which use C++11 features not present in the 4.6 series.

share|improve this question
    
+1: I can't compile gcc trunk with the error-msg: /usr/bin/ld: cannot find crti.o: No such file or directory. Figuring out the correct configure-command is particularly painful, since it takes 20 minutes before the compile breaks. –  mirk Nov 10 '11 at 20:05

4 Answers 4

up vote 2 down vote accepted
+50

Apply this patch, and configure with --enable-multiarch (not to be confused with multilib):

(That supersedes this earlier patch.)

share|improve this answer
    
And, if you don't like patching your sources, and setting flags aren't working for you, just soft-link crt*.o into the /usr/lib dirctory (you'll find them in either /usr/lib/i386-linux-gnu or /usr/lib/x86_64-linux-gnu). –  ams Nov 15 '11 at 14:55
    
I'm using Debian now so I can't check whether it works, but it looks OK so I'll accept it. –  Raphael R. Dec 6 '11 at 15:27

Some more material at:

http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=644986

Rather than using the whole script, the key part seems to be:

make FLAGS_FOR_TARGET="-B/usr/lib/i386-linux-gnu -I/usr/include/i386-linux-gnu"

The result is not entirely clean because it still needs a wrapper script after installation to execute with the right additional options. For example here is the example from the article /usr/bin/gcc-4.7 :

#!/bin/sh

exec /opt/gcc-4.7/bin/gcc-4.7 -B/usr/lib/i386-linux-gnu -I/usr/include/i386-linux-gnu "$@"
share|improve this answer

Ubuntu 11.10 brings multi-arch support which means that you shouldn't put library files in /usr/lib but /usr/lib/i386-linux-gnu (32-bit) or /usr/lib/x86_64-linux-gnu (64-bit).

Use something like:

CFLAGS=-I/usr/include/i386-linux-gnu ./configure [options]

You probably need to specify LDFLAGS=-L/usr/lib/i386-linux-gnu too.

Aside: your paths do not look pretty: /usr/i686-pc-linux-gnu/lib/, you might want to use options like --libdir to correct it.

share|improve this answer
    
It was actually added in 11.04, but 11.10 was when things were complete. –  jrg Oct 19 '11 at 19:09
    
Hmmm. The CFLAGS work, but if I set LDFLAGS it still can't find the crti.o . Also, the LDFLAGS don't appear in the command which links the libgcc_s.so . Then I added the -L/usr/lib/i386-linux-gnu to the CFLAGS. Now it appears in the command, but it STILL can't find it. I double-checked the path. It looks like gcc doesn't look at the -L paths when searching for .o files. –  Raphael R. Oct 19 '11 at 19:16
    
Then I'm out of ideas. Perhaps it's the scripts used for building gcc on Ubuntu show what you need (apt-get source --diff-only gcc, then run tar xf ... if it's a tarball and patch -p0 < ... if it's a diff file) –  Lekensteyn Oct 19 '11 at 19:27

Since your building from SVN, are you sure your building from the same revision? AKA, make sure the issue isn't upstream :-)

share|improve this answer
    
We are most likely not building from the same revision. We are unable to figure out reasonable ./configure command-options to complete a build with the new multiarch layout of Debian/Ubuntu. –  mirk Nov 12 '11 at 8:36

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.