Linker Complains Undefined Reference Under MINIX3.2.1

308 Views Asked by At

As you may imagine, it's a homework of Operating Systems and I'm asked to add function key Shift+F7 to show the number of running process.

I read the source code of command ps on GitHub (MINIX version 3.2.1) and try to implement a function that can finish the task in file /usr/src/servers/is/dmp_kernel.c. However, when I try to run make, it complains about undefined reference like

dmp_kernel.o: In function `running_proc_num':
dmp_kernel.c:(.text+0x1e): undefined reference to `chdir'
dmp_kernel.c:(.text+0x42): undefined reference to `fopen'
dmp_kernel.c:(.text+0x72): undefined reference to `fscanf'
dmp_kernel.c:(.text+0x8b): undefined reference to `fclose'
dmp_kernel.c:(.text+0xc4): undefined reference to `log10'
dmp_kernel.c:(.text+0xcc): undefined reference to `ceil'
dmp_kernel.c:(.text+0x119): undefined reference to `log10'
dmp_kernel.c:(.text+0x121): undefined reference to `ceil'
dmp_kernel.c:(.text+0x170): undefined reference to `fopen'
dmp_kernel.c:(.text+0x1bc): undefined reference to `fscanf'
dmp_kernel.c:(.text+0x1d3): undefined reference to `fclose'
dmp_kernel.c:(.text+0x210): undefined reference to `wait'
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I've already include the headers like stdio.h, math.h, unistd.h, and sys/wait.h. In the answer to one Stack Overflow question, I learnt that the reason for this issue is that the linker doesn't link a complete C library under MINIX. However, I usually use CMake and really have no idea to solve such issue. I don't even know how to "explicitly" link the functions using make.

I really look forward for your help!


The Makefile looks like


.include <bsd.own.mk>

PROG=   is
SRCS=   main.c dmp.c dmp_kernel.c dmp_pm.c dmp_fs.c dmp_rs.c dmp_ds.c dmp_vm.c

DPADD+= ${LIBSYS}
LDADD+= -lsys

MAN=

BINDIR?= /sbin

CPPFLAGS.dmp_kernel.c+= -I${NETBSDSRCDIR}
CPPFLAGS.dmp_rs.c+=     -I${NETBSDSRCDIR}
CPPFLAGS.dmp_vm.c+=     -I${NETBSDSRCDIR}

# This setting must match the kernel's, as it affects the IRQ hooks table size.
.if ${USE_APIC} != "no"
CFLAGS+= -DUSE_APIC
.endif

.include <minix.service.mk>
0

There are 0 best solutions below