Search code examples
coperating-systemxv6

xv6 makefile says undefined reference to __printf_chk


I'm trying to add a user space program in xv6, but when I try to compile it gives error: "/usr/include/bits/stdio2.h:104: undefined reference to __printf_chk". Any help? My user program:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/stat.h>
#include <sys/user.h>

int 
main(int argc, char *argv[])
{
    setbuf(stdout, NULL);
    for (int i = 1; i < argc; i++)
    {
         printf("Print in user space: %s\n", argv[0]);
    }
    exit(0);

    return 0;
}



Solution

  • You've compiled the program with your host headers, which are from glibc, but you're trying to link it with the xv6 target libraries. That's not going to work. You need to be using a proper cross compiler and taking care not to pollute it with -I options that would bring in host headers or -L options that would bring in host libraries.