NT->Linux Cross egcs: ld: cannot open -lc

Kai Ruottu karuottu@freenet.hut.fi
Fri Jul 9 05:29:00 GMT 1999


> (1) Using a simple hello.cpp test file I am able to produce an object file
> with the compiler -c option; (i.e. i586-linux-gnu-gcc -c hello.cpp) However,
> when I try to produce an executable I get the following error:
> 
> -----
> /butils/bin/i586-linux-gnu-ld: cannot open -lc: No such file or directory
> collect2: ld returned 1 exit status
> -----

 Please try 'i586-linux-gnu-gcc -print-search-dirs' to see the library search 
path...  Your Linux libs should be somewhere out there. Another useful option
is the '-verbose' for the linker. You can give it in the GCC-command using the
'-Wl' option :

    i586-linux-gnu-gcc -Wl,-verbose -o myprog.x myprog.c

It shows all the tries and succeedings during the link...

> (2) When I copy the hello.o to my Linux box and try to link it with: ld -o
> output /usr/lib/crt1.o hello.o -lc
> I get the following undefined reference errors; for example:
> 
> -----
> hello.o: In function `main':
> hello.o(.text+0x4): undefined reference to `endl(ostream &)'
> hello.o(.text+0xe): undefined reference to `cout'
> hello.o(.text+0x13): undefined reference to `ostream::operator<<(char const
> *)'
> hello.o(.text+0x1e): undefined reference to `ostream::operator<<(ostream
> &(*)(ostream &))'
> -----
> Presumably, the cause of this is  the linker not finding the relevant
> libraries, and not a problem with the compiled object code???

 Yes, you must use the '-lstdc++' with C++, or link using 'g++'

     g++ -o output hello.o

Besides, you would need to add the 'crti.o', 'crtbegin.o', 'crtend.o' and 
'crtn.o' too, if using 'ld' to link... Adding '-v' to the previous command
and seeing the link command will tell what it links as default...

> The directory /butils is the location of the binutils products. I downloaded
> glibc-2.0.bin.i386.tgz and utarred that into my root (C:) directory, so I
> have C:\usr. I also copied the /usr/include/linux and /usr/include/asm
> directories from my Linux machine to C:\usr\include\linux and
> C:\usr\include\asm respectively. Am I right to use the glibc-2.0.bin.i386?

 Perhaps, perhaps not... It depends on what you want to do with the 
compiler. If you want to produce binaries for many Linux machines, you should
select a glibc-2.x- (or even a libc5-) release which serves all of them... If 
the compatibility with your own Linux-machine is the only need, you just copy 
the libs and headers from it...  The WordPerfect 8 for Linux is libc5-based,
StarOffice5 is glibc-2.0.7-based, so there isn't a common agreement about what 
are 'Linux-binaries'...

 But you should never mix the libs and headers from different glibc-releases, 
as you now seem to do by taking the libs from the '.tgz' and headers from your
own machine. How on earth the '.tgz' file didn't have the headers ?

 Anyway the 'i586-linux-gnu-gcc -print-search-dirs' will tell the search 
directories for the libs (includes too...). Just follow them... The general 
rule is to use:

  <prefix>/<target>/bin                    for binutils
  <prefix>/<target>/lib                    for libraries
  <prefix>/<target>/include                for includes
and
  <prefix>/lib/gcc-lib/<target>/<version>  for cc1*, cpp, collect2, libgcc.a

 Your <target> is 'i586-linux-gnu', but guessing what you gave for 
'--prefix=xxxx' is hard... If nothing, the <prefix> is '/usr/local'... The 
'-print-search-dirs' will tell it to you...

> Do I need something else in addition to these?

 Don't forget to add the '-rpath-link <prefix>/i586-linux-gnu/lib' into 
your '*link:' in the 'specs' file, and copy the 'ld-linux.so.2' there.
Putting it into '/lib', just as in Linux, may be an alternative, but keeping
all the libs in the same place will be easier.

Cheers, Kai

 
_______________________________________________
New CrossGCC FAQ: http://www.objsw.com/CrossGCC
_______________________________________________
To remove yourself from the crossgcc list, send
mail to crossgcc-request@cygnus.com with the
text 'unsubscribe' (without the quotes) in the
body of the message.


More information about the crossgcc mailing list