How to force ld to find crti.o

Daniel Kegel
Fri Jan 23 18:27:00 GMT 2004

Roman Duka wrote:
> hi guys, i have a question regarding ld and crti.o
> i've built cross binutils, bootstrap gcc, and glibc, but i'm having 
> problems building final gcc. 

First off, have you considered running my build script,
It ought to work for you...

 > the problems are due to my cross glibc
> being installed in prefix/target/lib and prefix/target/usr/lib (when the 
> entire glibc in installed in only prefix/target/lib the final gcc builds 
> OK)

Ah, the joys of the /lib /usr/lib split.

> i get the following error message when i try to build final gcc
> /home/roman/crosstool/sparc-unknown/sparc-unknown-linux-gnu/bin/ld: 
> cannot open crti.o: No such file or directory
> collect2: ld returned 1 exit status
> make[2]: *** [] Error 1
> make[2]: Leaving directory `/home/roman/crosstool/build/gcc-build/gcc'
> make[1]: *** [libgcc.a] Error 2
> make[1]: Leaving directory `/home/roman/crosstool/build/gcc-build/gcc'
> make: *** [all-gcc] Error 2
> so i'm guessing ld cannot locate crti.o, even though crti.o exists under 
> prefix/target/usr/lib!! When building binutils i used "make 
> LIB_PATH=prefix/target/usr/lib" to tell ld where to look for libraries 
> etc. Checking ld for SEARCH_DIR shows that it knows about the relevant 
> paths
> athlon1000:/home/roman/crosstool/sparc-unknown/sparc-unknown-linux-gnu/bin 
> # ./ld --verbose
> GNU ld version 2.14 20030612
>   Supported emulations:
>    elf32_sparc
>    sparclinux
>    elf64_sparc
>    sun4
> using internal linker script:
> ==================================================
> /* Script for -z combreloc: combine and sort reloc sections */
> OUTPUT_FORMAT("elf32-sparc", "elf32-sparc",
>               "elf32-sparc")
> OUTPUT_ARCH(sparc)
> ENTRY(_start)
> SEARCH_DIR("/home/roman/crosstool/sparc-unknown/sparc-unknown-linux-gnu/lib"); 
> SEARCH_DIR("/home/roman/crosstool/sparc-unknown/sparc-unknown-linux-gnu/usr/lib"); 
> .... etc
> Does anybody know how to force ld to see the files under my 
> prefix/target/usr/lib? I've specified all the paths etc, but from the 
> error messages above it looks like ld doesn't pay much attention to 
> them!!!!

For what it's worth, I found that the new --with-sysroot option helped
when trying to live with the /lib - /usr/lib split.  This is in gcc-3.3.3 and up.
See how I used it in crosstool-0.26.

However, on the off chance your problem is a simple one, you might consider
making a minimal shell script to reproduce the problem, then running
it under strace -f -o foo.log
and grep for crti.o.
That will tell you where it's really looking.
You might find that it's gcc.c that is supposed to locate crti.o, and
is failing to pass an absolute path to ld.  (I can't remember if
crti.o is one of those files gcc.c has to find.)  If so, you
should use the --print-file-name=crti.o option of gcc to test
its path search, and concentrate on that.
- Dan

Want more information?  See the CrossGCC FAQ,
Want to unsubscribe? Send a note to

More information about the crossgcc mailing list