title: Undefined reference to `usbInit' in C AVR
body: <p>I use v-usb library for my project.
  I wrote code and i want compile it, but unfortunately I have an error which I'm unable to resolve.
  Here is my screen-shot:</p>
  
  <p><img src="https://i.stack.imgur.com/ZTR9Q.png" alt="enter image description here"></p>
  
  <pre><code>Description Resource    Path    Location    Type
  make: *** [USB_module.elf] Error 1  USB_module          C/C++ Problem
  undefined reference to `usbInit'    main.c  /USB_module     C/C++ Problem
  undefined reference to `usbMsgPtr'  main.c  /USB_module     C/C++ Problem
  undefined reference to `usbPoll'    main.c  /USB_module     C/C++ Problem
  </code></pre>
  
  <p>This situation is for me strange because i have in header this:</p>
  
  <pre><code>#include "usbconfig.h"
  #include "usbdrv/usbdrv.h"
  #include "usbdrv/oddebug.h"
  </code></pre>
  
  <p>And <code>usbdrv/usbdrv.h</code> defines the <code>USBpoll</code> function: <img src="https://i.stack.imgur.com/peWP9.png" width="200" /></p>
  
  <p>Shouldn't the compiler be able to compile it?</p>
  
  <p>Here is my project: <a href="http://goo.gl/P6ujK" rel="nofollow noreferrer">http://goo.gl/P6ujK</a></p>
  
  <p>And here is my entire workspace directory: <a href="http://minus.com/mbhTkJuvOK#1" rel="nofollow noreferrer">http://minus.com/mbhTkJuvOK#1</a></p>
  
  <p>Here is my code: main.c:</p>
  
  <pre><code>/*
   * main.c
   *
   *  Created on: 25-01-2012
   *      Author: Bordeux
   */
  #define F_CPU 12000000
  #include &lt;avr/io.h&gt;
  #include &lt;avr/interrupt.h&gt;
  #include &lt;avr/pgmspace.h&gt;
  #include &lt;avr/wdt.h&gt;
  
  #include "usbconfig.h"
  #include "usbdrv/usbdrv.h"
  #include "usbdrv/oddebug.h"
  
  
  #define DDS1_SDA (1&lt;&lt;1)          //PORTB1
  #define DDS_SCL  (1&lt;&lt;3)          //PORTB3
  #define DDS_UPDATE (1&lt;&lt;4)        //PORTB4
  
  static uchar usb_val;
  
  USB_PUBLIC uchar usbFunctionWrite(uchar *data, uchar len) //sends len bytes to DDS_SDA
  {
      uchar i;
      uchar b;
      uchar adr=0;
      while (len!=0)
      {
          b=1;
          for (i=0; i&lt;8; i++)
          {
              if (b &amp; data[adr])
              {
                  PORTB = (PORTB | DDS1_SDA) &amp; ~DDS_SCL;
                  PORTB = PORTB | DDS_SCL;
              }
              else
              {
                  PORTB = PORTB &amp; (~DDS1_SDA &amp; ~DDS_SCL);
                  PORTB = PORTB | DDS_SCL;
              }
              b=b&lt;&lt;1;
          }
          len--;
          adr++;
      }
      if (usb_val)
      {
          PORTB = PORTB | DDS_UPDATE;// update DDS
          PORTB = PORTB &amp; ~DDS_UPDATE;
      }
      return 1;
  }
  
  
  USB_PUBLIC uchar usbFunctionSetup(uchar data[8])
  {
      usbRequest_t *rq = (void *)data;
      static uchar    replyBuf[3];
      usbMsgPtr = replyBuf;
      if(rq-&gt;bRequest == 0)         // ECHO value
      {
          replyBuf[0] = data[2];    // rq-&gt;bRequest identical data[1]!
          replyBuf[1] = data[3];
          return 2;
      }
      if(rq-&gt;bRequest == 1)         // set port directions
      {
          // DDRA = data[2];
          DDRB = data[3];            
          DDRD = data[4] &amp; (~USBMASK &amp; ~(1 &lt;&lt; 2)); // protect USB interface
          return 0;
      }
      if(rq-&gt;bRequest == 2)         // read ports
      {
          // replyBuf[0] = PINA;
          replyBuf[1] = PINB;
          replyBuf[2] = PIND;
          return 3;
      }
      if(rq-&gt;bRequest == 3)         // read port states
      {
          // replyBuf[0] = PORTA;
          replyBuf[1] = PORTB;
          replyBuf[2] = PORTD;
          return 3;
      }
      if(rq-&gt;bRequest == 4)         // set ports
      {
          // PORTA = data[2];
          PORTB = data[3];
          PORTD = data[4];
          return 0;
      }
      if(rq-&gt;bRequest == 5)        // use usbFunctionWrite to transfer len bytes to DDS
      {
          usb_val = data[2];       // usb_val!=0 =&gt; DDS update pulse after data transfer
          return 0xff;
      }
      if(rq-&gt;bRequest == 6)
      {
          PORTB = PORTB | DDS_UPDATE;  // issue update pulse to DDS
          PORTB = PORTB &amp; ~DDS_UPDATE;
          return 0;
      }
      replyBuf[0] = 0xff;          // return value 0xff =&gt; command not supported
      return 1;
  }
  
  
  int main(void)
  {
      wdt_enable(WDTO_1S);         // set Watchdog Timer
      odDebugInit();
      PORTB=0xe0;                  // Set PortB 0-4 zero
      DDRB=0x1f;                   // Set PORTB 0-4 output
      PORTD = 0;                   /* no pullups on USB pins                     */
      DDRD = ~USBMASK &amp; ~(1 &lt;&lt; 2); /* all outputs except USB data and PD2 = INT0 */
      usbInit();
      sei();
      for(;;)                      /* main event loop                            */
      {
          wdt_reset();             // restart watchdog timer
          usbPoll();
      }
      return 0;
  }
  </code></pre>