1

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>
citrate
  • 189
  • 1
  • 1
  • 8
  • It's probably a Makefile issue, so you need to look in the Makefile. -l is usually used to link libraries. – resiliware Sep 24 '20 at 14:44
  • You need to find out which library contains the missing function. Then add it to the list of libraries. – the busybee Sep 24 '20 at 15:29
  • Well. I used another method to solve the homework, but I still don't know how to explicitly link a library by makefile. – citrate Sep 26 '20 at 07:03

0 Answers0