First off, some specifics:
Gcc: cross compiled under Cygwin to support plain binary
Environment: freestanding/ Part of OS development
parameters to gcc: -nostdlib -nostartfiles -nostdinc
So here goes the problem:
Now that I've a minimal C library implemented I decided to create a static library. For all function call appearing in the library, I've corresponding header files. All functions in a particular header file (and corresponding .c file before creating the library) are standalone and hence make calls only to the functions available within that file only. No external calls. I compiled all the source files with -c parameter and created a static library with:
ar rcs libstatic.a *.o
This generates libstatic.a. But now whenever I try to link this library with my source files using ld, ld throws and error text+xxx: Undefined reference to xxx. This happens for all calls to function that are available in the static library. Note that, I've #include the corresponding header files that have the function definition.
That being said, if I link the object files instead of the library, everything goes well; no errors, no warnings. So I presume somehow the library is not being created as I've expected!
So, if anyone has any insight on this matter, please respond. Thank you in advance!
gcc static library binding failure
Re: gcc static library binding failure
What is the exact command you are using for the link?
- Combuster
- Member
- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
Re: gcc static library binding failure
Start with actually using the cross-compiler, thank you.ar
Re: gcc static library binding failure
The archiver is a part of cross compiled binaries. Literally, it should be able to archive the cross compiled object files.Combuster wrote:Start with actually using the cross-compiler, thank you.ar
ld -T xxx.ld -o xxx xx1.o xx2.o xx3.o xxx.o --library=staticiansjack wrote:What is the exact command you are using for the link?
Anyway, I fixed the problem by specifying library search path using -L switch to ld. I assumed that the default search path would be the current directory. Nevertheless, it is strange that neither ld nor gcc complains on missing library even if it is unable to find the library file I'm specifying.
Still, thank you for your responses.
Re: gcc static library binding failure
I think this is consistent with the behaviour of Unix elsewhere. Bear in mind that "--library=static" isn't saying "link library libstatic into the executable"; rather it is saying "include library libstatic in the list of places to search for unresolved symbols". If you include a non-existing directory name in the PATH environment variable, bash doesn't produce a warning about this; so ld doesn't warn you if you specify a (possible) search location that doesn't exist. Again, it is consistent that "." isn't, by default, included in the search path.Rival wrote:Nevertheless, it is strange that neither ld nor gcc complains on missing library even if it is unable to find the library file I'm specifying.