GRUB Error 13, can't statically link either

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
milkcool
Posts: 1
Joined: Thu Jul 20, 2023 4:16 am

GRUB Error 13, can't statically link either

Post by milkcool »

Hello everyone! I'm new to os development also new to this forum. I've tried everything I could find online, but couldn't succeed.
When I'm compiling, linking and booting my OS GRUB gives me the error 13. I am trying to follow this tutorial https://hasinisama.medium.com/building- ... 6425adb084 (this is the 2nd part), but I'm trying to include standard C libraries as well as trying to make the system 64 bit.
kernel/main.c: https://pastebin.com/ceQjSGnJ
loader.s: https://pastebin.com/PUYi48Ve
Makefile: https://pastebin.com/GyHjPDmd
link.ld: https://pastebin.com/2qxCebER
What am I doing wrong? Thanks in advance :)
Octocontrabass
Member
Member
Posts: 5218
Joined: Mon Mar 25, 2013 7:01 pm

Re: GRUB Error 13, can't statically link either

Post by Octocontrabass »

milkcool wrote:What am I doing wrong?
  • Following a tutorial
  • Trying to include standard C libraries
  • Not switching to 64-bit mode
Most tutorials focused on or around OS development have mistakes. Usually the author is a beginner like you, documenting their process as they go, including their mistakes that they haven't noticed yet. Most tutorial authors give up before they reach the point where they could go back and correct their mistakes.

Standard C libraries depend on an OS. You're trying to include standard C libraries designed to run on Linux. Your OS is not compatible with Linux (for now), so the Linux C libraries won't work. You can use freestanding C headers; those don't depend on an OS.

Multiboot says the CPU starts in 32-bit mode. You have to switch the CPU into 64-bit mode before you can run 64-bit code. Switching to 64-bit mode is not exactly simple; you need to set up a GDT and some page tables, and mess with a handful of control registers. If you really want to write a 64-bit OS, you might have an easier time if you use a bootloader that can handle switching to 64-bit mode (such as Limine). You'll still need to set up a GDT and some page tables eventually, but then you can put it off until you're more familiar with x86.
davmac314
Member
Member
Posts: 118
Joined: Mon Jul 05, 2021 6:57 pm

Re: GRUB Error 13, can't statically link either

Post by davmac314 »

You cannot use a system C library, designed to work in programs running in user space under a particular kernel, in your own kernel which does not run under that kernel.
Post Reply