对“usbInit”的未定义引用在CAVR中

发布于 2024-12-29 03:09:31 字数 4388 浏览 1 评论 0 原文

我在我的项目中使用 v-usb 库。 我编写了代码并想编译它,但不幸的是我有一个无法解决的错误。 这是我的屏幕截图:

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

这种情况对我来说很奇怪,因为我在标题中有这样的:

#include "usbconfig.h"
#include "usbdrv/usbdrv.h"
#include "usbdrv/oddebug.h"

并且< code>usbdrv/usbdrv.h 定义了 USBpoll 函数:

应该'编译器是能编译吗?

这是我的项目:http://goo.gl/P6ujK

这是我的整个工作区目录:http://minus.com/mbhTkJuvOK#1

这是我的代码:主要.c:

/*
 * main.c
 *
 *  Created on: 25-01-2012
 *      Author: Bordeux
 */
#define F_CPU 12000000
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include <avr/wdt.h>

#include "usbconfig.h"
#include "usbdrv/usbdrv.h"
#include "usbdrv/oddebug.h"


#define DDS1_SDA (1<<1)          //PORTB1
#define DDS_SCL  (1<<3)          //PORTB3
#define DDS_UPDATE (1<<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<8; i++)
        {
            if (b & data[adr])
            {
                PORTB = (PORTB | DDS1_SDA) & ~DDS_SCL;
                PORTB = PORTB | DDS_SCL;
            }
            else
            {
                PORTB = PORTB & (~DDS1_SDA & ~DDS_SCL);
                PORTB = PORTB | DDS_SCL;
            }
            b=b<<1;
        }
        len--;
        adr++;
    }
    if (usb_val)
    {
        PORTB = PORTB | DDS_UPDATE;// update DDS
        PORTB = PORTB & ~DDS_UPDATE;
    }
    return 1;
}


USB_PUBLIC uchar usbFunctionSetup(uchar data[8])
{
    usbRequest_t *rq = (void *)data;
    static uchar    replyBuf[3];
    usbMsgPtr = replyBuf;
    if(rq->bRequest == 0)         // ECHO value
    {
        replyBuf[0] = data[2];    // rq->bRequest identical data[1]!
        replyBuf[1] = data[3];
        return 2;
    }
    if(rq->bRequest == 1)         // set port directions
    {
        // DDRA = data[2];
        DDRB = data[3];            
        DDRD = data[4] & (~USBMASK & ~(1 << 2)); // protect USB interface
        return 0;
    }
    if(rq->bRequest == 2)         // read ports
    {
        // replyBuf[0] = PINA;
        replyBuf[1] = PINB;
        replyBuf[2] = PIND;
        return 3;
    }
    if(rq->bRequest == 3)         // read port states
    {
        // replyBuf[0] = PORTA;
        replyBuf[1] = PORTB;
        replyBuf[2] = PORTD;
        return 3;
    }
    if(rq->bRequest == 4)         // set ports
    {
        // PORTA = data[2];
        PORTB = data[3];
        PORTD = data[4];
        return 0;
    }
    if(rq->bRequest == 5)        // use usbFunctionWrite to transfer len bytes to DDS
    {
        usb_val = data[2];       // usb_val!=0 => DDS update pulse after data transfer
        return 0xff;
    }
    if(rq->bRequest == 6)
    {
        PORTB = PORTB | DDS_UPDATE;  // issue update pulse to DDS
        PORTB = PORTB & ~DDS_UPDATE;
        return 0;
    }
    replyBuf[0] = 0xff;          // return value 0xff => 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 & ~(1 << 2); /* all outputs except USB data and PD2 = INT0 */
    usbInit();
    sei();
    for(;;)                      /* main event loop                            */
    {
        wdt_reset();             // restart watchdog timer
        usbPoll();
    }
    return 0;
}

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:

enter image description here

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

This situation is for me strange because i have in header this:

#include "usbconfig.h"
#include "usbdrv/usbdrv.h"
#include "usbdrv/oddebug.h"

And usbdrv/usbdrv.h defines the USBpoll function:

Shouldn't the compiler be able to compile it?

Here is my project: http://goo.gl/P6ujK

And here is my entire workspace directory: http://minus.com/mbhTkJuvOK#1

Here is my code: main.c:

/*
 * main.c
 *
 *  Created on: 25-01-2012
 *      Author: Bordeux
 */
#define F_CPU 12000000
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include <avr/wdt.h>

#include "usbconfig.h"
#include "usbdrv/usbdrv.h"
#include "usbdrv/oddebug.h"


#define DDS1_SDA (1<<1)          //PORTB1
#define DDS_SCL  (1<<3)          //PORTB3
#define DDS_UPDATE (1<<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<8; i++)
        {
            if (b & data[adr])
            {
                PORTB = (PORTB | DDS1_SDA) & ~DDS_SCL;
                PORTB = PORTB | DDS_SCL;
            }
            else
            {
                PORTB = PORTB & (~DDS1_SDA & ~DDS_SCL);
                PORTB = PORTB | DDS_SCL;
            }
            b=b<<1;
        }
        len--;
        adr++;
    }
    if (usb_val)
    {
        PORTB = PORTB | DDS_UPDATE;// update DDS
        PORTB = PORTB & ~DDS_UPDATE;
    }
    return 1;
}


USB_PUBLIC uchar usbFunctionSetup(uchar data[8])
{
    usbRequest_t *rq = (void *)data;
    static uchar    replyBuf[3];
    usbMsgPtr = replyBuf;
    if(rq->bRequest == 0)         // ECHO value
    {
        replyBuf[0] = data[2];    // rq->bRequest identical data[1]!
        replyBuf[1] = data[3];
        return 2;
    }
    if(rq->bRequest == 1)         // set port directions
    {
        // DDRA = data[2];
        DDRB = data[3];            
        DDRD = data[4] & (~USBMASK & ~(1 << 2)); // protect USB interface
        return 0;
    }
    if(rq->bRequest == 2)         // read ports
    {
        // replyBuf[0] = PINA;
        replyBuf[1] = PINB;
        replyBuf[2] = PIND;
        return 3;
    }
    if(rq->bRequest == 3)         // read port states
    {
        // replyBuf[0] = PORTA;
        replyBuf[1] = PORTB;
        replyBuf[2] = PORTD;
        return 3;
    }
    if(rq->bRequest == 4)         // set ports
    {
        // PORTA = data[2];
        PORTB = data[3];
        PORTD = data[4];
        return 0;
    }
    if(rq->bRequest == 5)        // use usbFunctionWrite to transfer len bytes to DDS
    {
        usb_val = data[2];       // usb_val!=0 => DDS update pulse after data transfer
        return 0xff;
    }
    if(rq->bRequest == 6)
    {
        PORTB = PORTB | DDS_UPDATE;  // issue update pulse to DDS
        PORTB = PORTB & ~DDS_UPDATE;
        return 0;
    }
    replyBuf[0] = 0xff;          // return value 0xff => 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 & ~(1 << 2); /* all outputs except USB data and PD2 = INT0 */
    usbInit();
    sei();
    for(;;)                      /* main event loop                            */
    {
        wdt_reset();             // restart watchdog timer
        usbPoll();
    }
    return 0;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

星軌x 2025-01-05 03:09:31

解决方案:

mv usbdrv.c usbdrv.cpp

或者使用avr-g++编译

solution:

mv usbdrv.c usbdrv.cpp

or compile with avr-g++

青春有你 2025-01-05 03:09:31

您需要链接任何提供 usbInit 等的文件,从屏幕截图来看,您已经显示了文件 usbdrv.c,但实际上并未将其编译/链接到您的项目中。树视图中仅显示 usbdrv.h。

#include 头文件向编译器显示函数的声明,您需要确保它也能在某处看到定义

You need to link against whatever file supplies usbInit etc., from the looks of your screen shots you've shown the file usbdrv.c, but not actually compiled/linked it into your project. Only usbdrv.h is showing in the tree view.

#includeing the header file shows the compiler the declaration of the function, you need to make sure it sees the definition somewhere too.

擦肩而过的背影 2025-01-05 03:09:31

您还可以将 usbdrv.h 包含在 extern "C" 中:

extern "C" {
   #include "usbdrv.h";
}

you could also have included usbdrv.h in extern "C":

extern "C" {
   #include "usbdrv.h";
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文