解决“重新声明为不同类型的符号"错误 [英] Solving "redeclared as different kind of symbol" error

查看:56
本文介绍了解决“重新声明为不同类型的符号"错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在研究 Arduino.我正在使用 Atmega1284 为 Lamp 工作.我看到了一个示例代码,ModbusIP_ENC28J60 -> Lamp.我首先编译它没有添加任何东西,它编译正确.现在,我正在添加 WebSocketServer,因为我希望它也能在 websocket 上工作.我添加了一些必要的行,但最终出现了这个错误:错误:EthernetClass Ethernet"重新声明为不同类型的符号

I'm currently working on Arduino. I'm working for Lamp using Atmega1284. I saw an example code, ModbusIP_ENC28J60 -> Lamp. I first compiled it without adding anything, it compiled properly. Now, I'm adding WebSocketServer, since I want this to work on websocket too. I added few necessary lines, but I ended up with this error: error: 'EthernetClass Ethernet' redeclared as different kind of symbol

我不明白代码有什么问题或我应该更改什么.有人可以帮我解决这个问题吗?

I don't understand what's wrong with the code or what I should change. Can someone help me with this?

我在这里粘贴我的代码以供参考:

I'm pasting my code here for reference:

#include <EtherCard.h>
#include <Modbus.h>
#include <ModbusIP_ENC28J60.h>

#include <WebSocketsServer.h>

WebSocketsServer webSocketServer = WebSocketsServer(8080);

//Modbus Registers Offsets (0-9999)
const int LAMP1_COIL = 100;
//Used Pins
const int ledPin = 9;

//ModbusIP object
ModbusIP mb;

void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght) {
    switch(type) {
        case WStype_DISCONNECTED:
            Serial.println("[%u] Disconnected!\n");
            break;
        case WStype_CONNECTED:
            {
                //IPAddress ip = webSocket.remoteIP(num);
            Serial.println("[%u] Disconnected!\n");

        // send message to client
        //webSocket.sendTXT(num, "Connected");
            }
            break;
        case WStype_TEXT:
            Serial.println("[%u] got text!\n");

            // send message to client
            // webSocket.sendTXT(num, "message here");

            // send data to all connected clients
            // webSocket.broadcastTXT("message here");
            break;
        case WStype_BIN:
            Serial.println("[%u] get binary ");
            //hexdump(payload, lenght);

            // send message to client
            // webSocket.sendBIN(num, payload, lenght);
            break;
    }
}

void setup() {
    // The media access control (ethernet hardware) address for the shield
    byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
    // The IP address for the shield
    byte ip[] = { 192, 168, 0, 120 };
    //Config Modbus IP
    mb.config(mac, ip);
    //Set ledPin mode
    pinMode(ledPin, OUTPUT);
    // Add LAMP1_COIL register - Use addCoil() for digital outputs
    mb.addCoil(LAMP1_COIL);

    webSocketServer.begin();
    webSocketServer.onEvent(webSocketEvent); 
}

void loop() {
   //Call once inside loop() - all magic here
   mb.task();

   //Attach ledPin to LAMP1_COIL register
   digitalWrite(ledPin, mb.Coil(LAMP1_COIL));

   webSocketServer.loop();
}

帮助我让它发挥作用.

推荐答案

您声明了两次以太网.而且它们是不同的.

You are declaring Ethernet twice. And they are different.

第一个可能在包含文件 Ethercard.h 中其次是Modbus.h

First is probably in the include file Ethercard.h Second is Modbus.h

在我通过 Google 在 github 中找到的 ModbusIP_ENC28J60 中,他们将以太网声明为一个数组.

In the ModbusIP_ENC28J60 I found in github via Google they declare Ethernet as an array.

要么重命名一个声明(例如以太与以太网),要么消除使用一个.此外,考虑到您的源代码中的包含文件,如果只有两个冲突,我会感到惊讶.

Either rename one declaration (e.g. ether vs Ethernet) or eliminate the use of one. Also, considering the include files in your source I would be surprised if there are only two conflicts.

C 课:声明一个变量供函数使用,非常简单.添加其他模块时,任何名称冲突都会导致问题.如果您让两个变量一致但仍在程序中,您将遭受大量调试难题,因为一个函数将访问其变量,而另一个将拥有自己的变量,从而导致实际上没有任何工作.

C lesson: Declaring a variable for use by a function, very straightforward. When adding additional modules any name conflicts will cause problems. If you get two variables to agree but are still in the program you will suffer massive debugging headaches because one function will access its variable while the other will have its own, resulting in nothing actually working.

返回查看源文件(*.h).搜索以太网"变量.看看它们是如何声明的以及它们是如何使用的.最简单的解决方案是选择最新的添加并将以太网更改为以太(正如我上面建议的那样).

Go back and look at the source files (*.h). Search for "Ethernet" variables. See how they are declared and how they are used. The simplest solution is to pick the latest addition and change Ethernet to ether (as I suggested above).

祝你好运.

这篇关于解决“重新声明为不同类型的符号"错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆