I have implemented kmalloc in the Makefile, defs.h, kmalloc.c, sysproc.c, usys.S, syscall.h, and syscall.c. I have a test case called test_1.c to test my implementation of kmalloc. I took the source code from xv6, I applied my implementations and changes, then run it on qemu.
I execute ./test-mmap.sh to know if I pass the test case. Turns out I didn't pass, I got error : "test_1.c: error: implicit declaration function of kmalloc". But I have implemented the kmalloc correctly and in the correct files. I am confuse, what am I missing here?
When compiling
test.cthe compiler (pre-processor) includes these files:None of those files have an explicit declaration for
kmalloc(), so the compiler complains about an implicit declaration ofkmalloc()when it sees it at line 18.There is an explicit declaration for
kmalloc()indefs.h(at line 81), but that file isn't included bytest.cso the compiler has no idea it exists.To solve this problem, either add
#include "defs.h"at the top oftest1.cor in something that is already included bytest1.c(e.g. maybe at the top ofsyscall.h); or add an explicit declaration ("void* kmalloc(uint);") at the top oftest1.cor in something that is already included bytest.c.Note that depending on how you solve the problem you may (or may not) end up with an "implicit declaration of kfree()" problem next; which can be solved in the same way.