I’m building a project using a GNU tool chain and everything works fine until I get to linking it, where the linker complains that it is missing/can’t find crti.o. This is not one of my object files, it seems to be related to libc but I can’t understand why it would need this crti.o, wouldn’t it use a library file, e.g. libc.a?
I’m cross compiling for the arm platform. I have the file in the toolchain, but how do I get the linker to include it?
crti.o is on one of the ‘libraries’ search path, but should it look for .o file on the library path?
Is the search path the same for gcc and ld?
crti.ois the bootstrap library, generally quite small. It’s usually statically linked into your binary. It should be found in/usr/lib.If you’re running a binary distribution they tend to put all the developer stuff into -dev packages (e.g. libc6-dev) as it’s not needed to run compiled programs, just to build them.
You’re not cross-compiling are you?
If you’re cross-compiling it’s usually a problem with gcc’s search path not matching where your crti.o is. It should have been built when the toolchain was. The first thing to check is
gcc -print-search-dirsand see if crti.o is in any of those paths.The linking is actually done by ld but it has its paths passed down to it by gcc. Probably the quickest way to find out what’s going on is compile a helloworld.c program and strace it to see what is getting passed to ld and see what’s going on.
Open the log file and search for crti.o, as you can see my non-cross compiler:
If you see a bunch of attempts to
open(...crti.o) = -1 ENOENT,ldis getting confused and you want to see where the path it’s opening came from…