0

I wrote GDT/IDT table loader for my own kernel, and I linked it with ld. But when I generate the binary, the error has appeared. ld.exe: desc_tablesc.o:desc_tables.c:(.text+0x1e7): undefined reference to `memcpy'

and here's my code:

#include "desc_tables.h"
#include "common.h"
#include <stdint.h>


static void init_idt()
{
   __idt_ptr.limit = sizeof(idt_entry) * 256 -1;
   __idt_ptr.base  = (u32int)&idt_entries;

   memset(&idt_entries, 0, sizeof(idt_entry)*256);

   idt_set_gate( 0, (u32int)isr0 , 0x08, 0x8E);
   . . .
   idt_set_gate( 31, (u32int)isr31, 0x08, 0x8E);

   idt_flush((u32int)&__idt_ptr);
}```
권민수
  • 31
  • 1
  • 5
  • 1
    did you try to include `#include ` for memory-related operations? There is where `memset`, and `memcpy` are defined. – campescassiano Apr 09 '20 at 14:04
  • how can i do it? – 권민수 Apr 09 '20 at 14:06
  • On the top of the `desc_tables.c` file. – campescassiano Apr 09 '20 at 14:07
  • 3
    Welcome to SO. Please be aware that a header does not provide any definition of a function. It only provides declarations. (normally). It only allows you to compile without error because the compiler knows that there is a function `memset` somewhere else. You have a linker problem. – Gerhardh Apr 09 '20 at 14:07
  • From the code snippet I assume you are using some embedded system. Normally `memset` etc. are automatically linked with your program. It seems that you need to specify the lib manually for your build environment. – Gerhardh Apr 09 '20 at 14:08
  • @campescassiano i miscopied the code. there was an include code. – 권민수 Apr 09 '20 at 14:09
  • @Gerhardh should i declare it in the ld command line? – 권민수 Apr 09 '20 at 14:12
  • i'm using standard library in i386 system.... – 권민수 Apr 09 '20 at 14:13
  • 4
    You need to check with the manual of your compiler/linker toolchain how to provide C standard library to the linker – Gerhardh Apr 09 '20 at 14:13
  • Ok i got it thank you for your help – 권민수 Apr 09 '20 at 14:15
  • 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) – Tsyvarev Apr 09 '20 at 14:27
  • 1
    It appears that you are writing your own operating system. You need to provide your own implementations of all standard library functions you use. – fuz Apr 09 '20 at 14:39

0 Answers0