title: How compile a user space program with kernel headers
body: <p>I need to test a usbfs device by using <code>ioctl</code>.
  I need use <code>ioctl(fd, USBDEVFS_REAPURBNDELAY, &amp;receive);</code>.
  But <code>USBDEVFS_REAPURBNDELAY</code> is defined in a kernel header, so I include some kernel file like that:</p>
  
  <pre><code>#include &lt;linux/usb.h&gt;
  #include &lt;linux/usbdevice_fs.h&gt;
  #include &lt;asm/byteorder.h&gt;
  #include &lt;linux/usb/ch9.h&gt;
  </code></pre>
  
  <p>and compile it with <code>gcc -g -I /usr/src/linux-3.4.4-2-pae/include/ -o /home/madper/kernel/usb/select_for_usb /home/madper/kernel/usb/select_for_usb.c</code>  </p>
  
  <p>It said <code>#warning "Attempt to use kernel headers from user space, see http://kernelnewbies.org/KernelHeaders" [-Wcpp]</code></p>
  
  <p>And folled by lots of errors, so, What's the right way to use kernel headers?</p>
  
  <pre><code>/usr/src/linux-3.4.4-2-pae/include/linux/mod_devicetable.h:21:2: error: unknown type name ‘kernel_ulong_t’
  /usr/src/linux-3.4.4-2-pae/include/linux/mod_devicetable.h:36:2: error: unknown type name ‘kernel_ulong_t’
  /usr/src/linux-3.4.4-2-pae/include/linux/mod_devicetable.h:37:33: error: ‘kernel_ulong_t’ undeclared here (not in a function)
  /usr/src/linux-3.4.4-2-pae/include/linux/mod_devicetable.h:37:3: error: requested alignment is not an integer constant
  /usr/src/linux-3.4.4-2-pae/include/linux/mod_devicetable.h:119:2: error: expected specifier-qualifier-list before ‘kernel_ulong_t’
  /usr/src/linux-3.4.4-2-pae/include/linux/mod_devicetable.h:141:2: error: expected specifier-qualifier-list before ‘kernel_ulong_t’
  /usr/src/linux-3.4.4-2-pae/include/linux/mod_devicetable.h:154:2: error: expected specifier-qualifier-list before ‘kernel_ulong_t’
  /usr/src/linux-3.4.4-2-pae/include/linux/mod_devicetable.h:168:2: error: expected specifier-qualifier-list before ‘kernel_ulong_t’
  /usr/src/linux-3.4.4-2-pae/include/linux/mod_devicetable.h:179:2: error: expected specifier-qualifier-list before ‘kernel_ulong_t’
  /usr/src/linux-3.4.4-2-pae/include/linux/mod_devicetable.h:187:2: error: expected specifier-qualifier-list before ‘kernel_ulong_t’
  /usr/src/linux-3.4.4-2-pae/include/linux/mod_devicetable.h:195:2: error: expected specifier-qualifier-list before ‘kernel_ulong_t’
  /usr/src/linux-3.4.4-2-pae/include/linux/mod_devicetable.h:200:2: error: expected specifier-qualifier-list before ‘kernel_ulong_t’
  /usr/src/linux-3.4.4-2-pae/include/linux/mod_devicetable.h:227:2: error: expected specifier-qualifier-list before ‘kernel_ulong_t’
  /usr/src/linux-3.4.4-2-pae/include/linux/mod_devicetable.h:260:2: error: expected specifier-qualifier-list before ‘kernel_ulong_t’
  /usr/src/linux-3.4.4-2-pae/include/linux/mod_devicetable.h:314:2: error: expected specifier-qualifier-list before ‘kernel_ulong_t’
  /usr/src/linux-3.4.4-2-pae/include/linux/mod_devicetable.h:341:2: error: expected specifier-qualifier-list before ‘kernel_ulong_t’
  /usr/src/linux-3.4.4-2-pae/include/linux/mod_devicetable.h:366:2: error: expected specifier-qualifier-list before ‘kernel_ulong_t’
  /usr/src/linux-3.4.4-2-pae/include/linux/mod_devicetable.h:413:2: error: expected specifier-qualifier-list before ‘kernel_ulong_t’
  /usr/src/linux-3.4.4-2-pae/include/linux/mod_devicetable.h:433:2: error: expected specifier-qualifier-list before ‘kernel_ulong_t’
  /usr/src/linux-3.4.4-2-pae/include/linux/mod_devicetable.h:444:2: error: expected specifier-qualifier-list before ‘kernel_ulong_t’
  /usr/src/linux-3.4.4-2-pae/include/linux/mod_devicetable.h:479:2: error: expected specifier-qualifier-list before ‘kernel_ulong_t’
  /usr/src/linux-3.4.4-2-pae/include/linux/mod_devicetable.h:508:2: error: expected specifier-qualifier-list before ‘kernel_ulong_t’
  /usr/src/linux-3.4.4-2-pae/include/linux/mod_devicetable.h:540:2: error: expected specifier-qualifier-list before ‘kernel_ulong_t’
  /usr/src/linux-3.4.4-2-pae/include/linux/mod_devicetable.h:551:2: error: expected specifier-qualifier-list before ‘kernel_ulong_t’
  /usr/src/linux-3.4.4-2-pae/include/linux/mod_devicetable.h:566:2: error: expected specifier-qualifier-list before ‘kernel_ulong_t’
  /usr/src/linux-3.4.4-2-pae/include/linux/mod_devicetable.h:582:2: error: expected specifier-qualifier-list before ‘kernel_ulong_t’
  /home/madper/kernel/usb/select_for_usb.c: In function ‘main’:
  /home/madper/kernel/usb/select_for_usb.c:46:30: error: expected expression before ‘void’
  </code></pre>