title: Linux Device Driver: Symbol "memcpy" not found
body: <p>I'm trying to write a Linux device driver. I've got it to work really well, until I tried to use "memcpy". I don't even get a compiler error, when I "make" it just warns me: </p>
  
  <p><code>WARNING: "memcpy" [/root/homedir/sv/main.ko] undefined!</code></p>
  
  <p>OK and when I try to load via insmod, I get on the console:</p>
  
  <p><code>insmod: error inserting './main.ko': -1 Unknown symbol in module</code></p>
  
  <p>and on dmesg:</p>
  
  <p><code>main: Unknown symbol memcpy (err 0)</code></p>
  
  <p>I include the following:</p>
  
  <pre><code>#include &lt;linux/module.h&gt;
  #include &lt;linux/moduleparam.h&gt;
  #include &lt;linux/init.h&gt;
  
  #include &lt;linux/kernel.h&gt; /* printk() */
  #include &lt;linux/slab.h&gt;  /* kmalloc() */
  #include &lt;linux/fs.h&gt;  /* everything... */
  #include &lt;linux/errno.h&gt; /* error codes */
  #include &lt;linux/types.h&gt; /* size_t */
  #include &lt;linux/fcntl.h&gt; /* O_ACCMODE */
  #include &lt;linux/cdev.h&gt;
  #include &lt;asm/system.h&gt;  /* cli(), *_flags */
  #include &lt;asm/uaccess.h&gt; /* copy_*_user */
  </code></pre>
  
  <p>The function using memcpy:</p>
  
  <pre><code>static int dc_copy_to_user(char __user *buf, size_t count, loff_t *f_pos, 
          struct sv_data_dev *dev)
  {
      char data[MAX_KEYLEN];
      size_t i = 0;
  
      /* Copy the bulk as long as there are 10 more bytes to copy */
      while (i &lt; (count + MAX_KEYLEN)) {
          memcpy(data, &amp;dev-&gt;data[*f_pos + i], MAX_KEYLEN);
          ec_block(dev-&gt;key, data, MAX_KEYLEN);
          if (copy_to_user(&amp;buf[i], data, MAX_KEYLEN)) {
              return -EFAULT;
          }
          i += MAX_KEYLEN;
       }
  
       return 0;
   }
  </code></pre>
  
  <p>Could someone help me? I thought the thing was in linux/string.h, but I get the error just the same. I'm using kernel 2.6.37-rc1 (I'm doing in in user-mode-linux, which works only since 2.6.37-rc1). Any help is greatly appreciated. </p>
  
  <pre><code># Context dependent makefile that can be called directly and will invoke itself
  # through the kernel module building system.
  KERNELDIR=/usr/src/linux
  
  ifneq ($(KERNELRELEASE),)
  
  EXTRA_CFLAGS+=-I $(PWD) -ARCH=um
  obj-m := main.o
  
  else
  
  KERNELDIR ?= /lib/modules/$(shell uname -r)/build
  PWD = $(shell pwd)
  
  all:
   $(MAKE) V=1 ARCH=um -C $(KERNELDIR) M=$(PWD) modules
  
  clean:
   rm -rf Module.symvers .*.cmd *.ko .*.o *.o *.mod.c .tmp_versions *.order
  
  endif
  </code></pre>