MeatySkeleton linking libc libraries

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
MuchLearning
Member
Member
Posts: 26
Joined: Sun Feb 12, 2017 1:50 am

MeatySkeleton linking libc libraries

Post by MuchLearning »

I've been stepping through the MeatySkeleton Tutorial trying to understand each piece. I think I've got most of it down but I don't understand how the functions included in libc get linked when compiling the kernel.

I'm trying to recreate my own version of MeatySkeleton and when compiling the kernel I get 'undefined reference to ...' for anything from the libc directory.
User avatar
iansjack
Member
Member
Posts: 4706
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: MeatySkeleton linking libc libraries

Post by iansjack »

As the tutorial explains, if you want to use kind functions you need to create your own kind.
User avatar
MuchLearning
Member
Member
Posts: 26
Joined: Sun Feb 12, 2017 1:50 am

Re: MeatySkeleton linking libc libraries

Post by MuchLearning »

I have written headers and sources for the functions I am trying to use. With all headers installed my sysroot looks something like

Code: Select all

sysroot/
    usr/
        include/
            stdio.h
            terminal.h
        lib/
            libk.a
And the function I'm attempting to use, printf, comes from stdio.h. Does this mean libk.a is not getting created correctly? Is that where the sources are being linked from?

*Edit*: the libk.a archive does contain printf.libk.o so I'm not sure what is happening.
StudlyCaps
Member
Member
Posts: 232
Joined: Mon Jul 25, 2016 6:54 pm
Location: Adelaide, Australia

Re: MeatySkeleton linking libc libraries

Post by StudlyCaps »

Do you have -lk in your $LIBS variable in kernel/Makefile?

edit: Or more precisely, when you build the kernel, is gcc being passed -lk.
User avatar
MuchLearning
Member
Member
Posts: 26
Joined: Sun Feb 12, 2017 1:50 am

Re: MeatySkeleton linking libc libraries

Post by MuchLearning »

StudlyCaps wrote:Do you have -lk in your $LIBS variable in kernel/Makefile?
StudlyCaps you indeed have the studliest of caps. I must have missed this flag.

What does it do? I can't find anything about what it does anywhere.
User avatar
iansjack
Member
Member
Posts: 4706
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: MeatySkeleton linking libc libraries

Post by iansjack »

It specifies that you want to link libk. You don't need to specify -lc as it is assumed.

In general, if you want to link libfoo you need -lfoo.
StudlyCaps
Member
Member
Posts: 232
Joined: Mon Jul 25, 2016 6:54 pm
Location: Adelaide, Australia

Re: MeatySkeleton linking libc libraries

Post by StudlyCaps »

:D You know I do :wink:

It tells the linker to link against a library named libk.

edit: beaten!
Post Reply