title: Linker Complains Undefined Reference Under MINIX3.2.1
body: <p>As you may imagine, it's a homework of Operating Systems and I'm asked to add function key <kbd>Shift</kbd>+<kbd>F7</kbd> to show the number of running process.</p>
  <p>I read the source code of command <code>ps</code> on <a href="https://github.com/jncraton/minix3/blob/master/commands/ps/ps.c" rel="nofollow noreferrer">GitHub</a> (MINIX version 3.2.1) and try to implement a function that can finish the task in file <code>/usr/src/servers/is/dmp_kernel.c</code>. However, when I try to run <code>make</code>, it complains about undefined reference like</p>
  <pre><code>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)
  </code></pre>
  <p>I've already include the headers like <code>stdio.h</code>, <code>math.h</code>, <code>unistd.h</code>, and <code>sys/wait.h</code>. In the <a href="https://stackoverflow.com/questions/26947282/minix-undefined-reference-to-strtok">answer</a> 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 <code>CMake</code> and really have no idea to solve such issue. I don't even know how to &quot;explicitly&quot; link the functions using <code>make</code>.</p>
  <p>I really look forward for your help!</p>
  <hr />
  <p>The <code>Makefile</code> looks like</p>
  <pre><code>
  .include &lt;bsd.own.mk&gt;
  
  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} != &quot;no&quot;
  CFLAGS+= -DUSE_APIC
  .endif
  
  .include &lt;minix.service.mk&gt;
  </code></pre>