1

can anyone help me solve this? It's just when I'm writing kernel code for my OS. When I'm writing stack for my kernel, here is the code: kernel.c

When I compiling it use this command:

gcc -m32 -c kernel.c -o kernel.o -std=gnu99 -ffreestanding -O2 -Wall -Wextra

It gives me this error:

ld: /home/lexuanloc/AmoreOS/cache/kernel.o: in function `MakeNode':
kernel.c:(.text+0xf2): undefined reference to `malloc'

ld: /home/lexuanloc/AmoreOS/cache/kernel.o: in function `screen_scrolling_up':
kernel.c:(.text+0x325): undefined reference to `Push'

ld: /home/lexuanloc/AmoreOS/cache/kernel.o: in function `screen_scrolling_up_when_press':
kernel.c:(.text+0x5d5): undefined reference to `Push'

ld: /home/lexuanloc/AmoreOS/cache/kernel.o: in function `screen_scrolling_down':
kernel.c:(.text+0x6d5): undefined reference to `Push'

ld: kernel.c:(.text+0x749): undefined reference to `load_fisrt_line'

Can anyone help me solve this?

  • You never defined `Push`, and you misspelled `first` as `fisrt` randomly. What were you expecting to happen? – Blindy Sep 15 '21 at 03:05
  • I have defined Push in line. 354. I want to push a line of text on the screen to the stack – NeonLightions Sep 15 '21 at 03:08
  • Does this answer your question? [What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – Ken White Sep 15 '21 at 03:17
  • That's will useful to me :D. Thanks! – NeonLightions Sep 15 '21 at 03:19
  • 1
    I'm not really sure , I should investigate on the matter , but -ffreestanding may disable some std functions and , if I'm not mistaken , malloc. For Push , you didn't define it , but declare it only in line 354 . Same thing for load_fisrt_line , you declared it , but didn't provide it's definition. – Amine Bensalem Sep 15 '21 at 03:48
  • 1
    Yeah, you can't use `malloc` or other `` functions in a kernel. You have to write your own memory allocation functions. – Nate Eldredge Sep 15 '21 at 05:55

0 Answers0