Getting C Library File to Work

Programming, for all ages and all languages.
Post Reply
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Getting C Library File to Work

Post by AJ »

Hi All,

I am creating a libc.a file for my OS and am trying to link it in with a my kernel to test it. I am asking in this forum as this seems more of a general C rather than an OS dev issue.

Every time I try to link it, I get the message:

Code: Select all

libc.a: could not read symbols: Memory Exhausted.
Which seems odd as so far I only have a single function in my libc!

I am building the library with DJGPP, using:

Code: Select all

gcc -Wall -c *.c
...and creating the archive with:

Code: Select all

ar rvs libc.a *.o
I attempt to link in my library with:

Code: Select all

ld -T link.ld -o bin\caracal.sys asm\kernel.o bin\*.o lib\*.o lib\*.a
Where the only parameter I have actually added is the 'lib\*.a'.

Does anyone have any ideas where I am going wrong?

Thanks,
Adam
User avatar
Brynet-Inc
Member
Member
Posts: 2426
Joined: Tue Oct 17, 2006 9:29 pm
Libera.chat IRC: brynet
Location: Canada
Contact:

Post by Brynet-Inc »

Hmm..

Turn on verbose and add the c option:

Code: Select all

ar vcrs libc.a *.o
Also try this after the above command:

Code: Select all

ranlib libc.a
Image
Twitter: @canadianbryan. Award by smcerm, I stole it. Original was larger.
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Post by AJ »

Thanks for the suggestions. Verbose mode does not seem to give any more information - ar itself completes fine.

I ran ranlib immediately afterwards as suggested but this did not seem to make a difference - I believe the 's' parameter does the same job? (could be wrong as I've not used ar before).

Adam
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Post by Candy »

AJ wrote:Thanks for the suggestions. Verbose mode does not seem to give any more information - ar itself completes fine.

I ran ranlib immediately afterwards as suggested but this did not seem to make a difference - I believe the 's' parameter does the same job? (could be wrong as I've not used ar before).
That's true. Most people don't use that because they tend to think along the lines of the old commands.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Post by Solar »

Hmmm... I use the equivalent of "gcc myprog.c libc.a -o myprog", which works fine. I would suggest first testing your toolchain with some simple "exercise" code outside your OS source tree, i.e. build a lib with one function in it and a main() that uses that function, and see that it links correctly without using your custom link.ld. Then work from there...
Every good solution is obvious once you've found it.
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Post by AJ »

Solar wrote:...build a lib with one function in it and a main() that uses that function, and see that it links correctly without using your custom link.ld. Then work from there...
Thanks - will do. In order to test my (very minimal - single function!) libc I have currently got around it by just linking the .o file in the normal way. Obviously when my libc grows, this is no good. I'll keep working the problem.

While I'm at it, I must remember to download your PDCLib to see how a library should be done...

Cheers,
Adam
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Post by Solar »

AJ wrote:While I'm at it, I must remember to download your PDCLib to see how a library should be done...
It's my first, so don't put too much trust into me doing it "right". For example, I don't create the symbol index as of v0.4.1, as I didn't know about that option prior to this thread. 8)
Every good solution is obvious once you've found it.
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Post by AJ »

For anyone in a similar situation, I think I have solved it. My C library contained system calls which were written in separate NASM modules instead of inline assembly.

For various reasons, I had NASM compiling in AOUT. Changing this seemed to make things go much more smoothly!

Cheers,
Adam
Post Reply