Reputation: 65
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;
}
Upvotes: 2
Views: 3896
Reputation: 1
for future reference i will answer dont include normal C header files you have to use headers provided by the xv6-libraries if u just include normal C headers you will get an error, more specifically delete the C headers and , if you are on RISC-V use #include "user/user.h"
Upvotes: 0
Reputation: 215193
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.
Upvotes: 4