title: Compiling Linux Kernel Module With A Custom Header
body: <p>I would like to compile a simple character device module depending on a custom header. The folder is thus organized,</p>
  
  <pre><code>+ mymod.c
  | customized-header.h
  | customized-header.c
  | Makefile
  </code></pre>
  
  <p>In <code>mymod.c</code>, the header is thus used,</p>
  
  <pre><code>#include "customized-header.h"
  </code></pre>
  
  <p>In Makefile:</p>
  
  <pre><code>obj-m := mymod.o
  mymod-objs := customized-header.o
  KVERSION = $(shell uname -r)
  PWD = $(shell pwd)
  all:
      make -C /lib/modules/$(KVERSION)/build M=$(PWD) modules
  clean:
      make -C /lib/modules/$(KVERSION)/build M=$(PWD) clean
  </code></pre>
  
  <p>Everything should work fine, the module gets compiled without problem, I can load the module through <code>sudo insmod</code>, but the module doesn't work properly. When I checked <code>nm mymod.ko</code>, there are a lot of vars and functions are missing. It looks as if it stopped after linking <code>customized_header.o</code>. If I remove this header and its function, say no header function calls from the module, it compiles perfectly with desired result.</p>
  
  <p>Could you see what went wrong here?</p>