OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Apr 25, 2024 4:20 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: gcc static library binding failure
PostPosted: Tue Mar 31, 2015 6:32 am 
Offline

Joined: Sat Feb 05, 2011 6:05 am
Posts: 11
Location: I gotta go
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!


Top
 Profile  
 
 Post subject: Re: gcc static library binding failure
PostPosted: Tue Mar 31, 2015 8:11 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4594
Location: Chichester, UK
What is the exact command you are using for the link?


Top
 Profile  
 
 Post subject: Re: gcc static library binding failure
PostPosted: Tue Mar 31, 2015 9:06 am 
Offline
Member
Member
User avatar

Joined: Wed Oct 18, 2006 3:45 am
Posts: 9301
Location: On the balcony, where I can actually keep 1½m distance
Quote:
ar
Start with actually using the cross-compiler, thank you.

_________________
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]


Top
 Profile  
 
 Post subject: Re: gcc static library binding failure
PostPosted: Wed Apr 01, 2015 12:31 am 
Offline

Joined: Sat Feb 05, 2011 6:05 am
Posts: 11
Location: I gotta go
Combuster wrote:
Quote:
ar
Start with actually using the cross-compiler, thank you.
The archiver is a part of cross compiled binaries. Literally, it should be able to archive the cross compiled object files.
iansjack wrote:
What is the exact command you are using for the link?

ld -T xxx.ld -o xxx xx1.o xx2.o xx3.o xxx.o --library=static

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.


Top
 Profile  
 
 Post subject: Re: gcc static library binding failure
PostPosted: Wed Apr 01, 2015 1:53 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4594
Location: Chichester, UK
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.

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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 146 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group