2017-03-08 1 views
-2

Arduino를 프로그래밍 중이므로이 오류 메시지가 나타날 때 나는 초보자이므로이를 해결하기 위해 해석 할 수 없습니다.컴파일러 링커 오류입니까?

"C : \ 사용자 토르 ~ 1.NUN \의 AppData \ 로컬 \ 임시 \의 ccmmwX2d.ltrans0.ltrans.o를 \ : 기능 setup': ccmmwX2d.ltrans0.o:(.text+0x16a): undefined reference to registrador_nivel '에서 C : \ 사용자 토르 ~ 1.NUN \의 AppData \를 \ 현지 \ 임시 \의 ccmmwX2d.ltrans4.ltrans.o : 기능 AutoCampLib::Registrador::debug(char*)': ccmmwX2d.ltrans4.o:(.text+0xae0): undefined reference to registrador_nivel '에서 collect2.exe : 오류 : 신분증 1 개 종료 상태를 반환 "

이 내 lib 디렉토리 :

#ifndef LIBAC_H 
#define LIBAC_H 
#define DEBUG 
/***************************************************/ 
/********************Bibliotecas********************/ 
/***************************************************/ 
/*   Biblioteca padrão do Arduino   */ 
#include <Arduino.h> 
/* Bibliotecas de data/hora para módulo DS1307 RTC */ 
#include <Wire.h> 
#include <RTClib.h> 
#include <Time.h> 
#include <TimeLib.h> 
#include <TimeAlarms.h> 


/* Bibliotecas de leitura e escrita para módulo SD */ 
#include <SD.h> 
#include <SPI.h> 
/* Biblioteca do módulo ultrassônico HC-SR04 */ 
#include <Ultrasonic.h> 
/* Biblioteca de Lista Encadeada */ 
#include <LinkedList.h> 
/* Biblioteca de Threads */ 
#include "Thread.h" 
#include "ThreadController.h" 

/* Biblioteca de HashMap */ 
#include <HashMap.h> 

/***************************************************/ 
/******************Mapa da Pinagem******************/ 
/***************************************************/ 

#define PINO_SD_CS 53 
#define setor_1 23 
#define setor_2 25 
#define setor_3 42 
#define setor_4 43 
#define setor_5 44 
#define setor_6 45 
#define setor_7 12 
#define setor_8 13 
#define setor_9 22 
#define setor_10 24 
#define setor_11 26 
#define setor_12 28 
#define setor_13 30 
#define setor_14 32 
#define setor_15 34 
#define DesligaBombaCaptacao 31 
#define LigaBombaCaptacao 33 
#define DesligaBombaInjec 35 
#define LigaBombaInjec 37 
#define valvulaDescarte 46 
#define DesligaPaMistura 39 
#define LigaPaMistura 41 
#define silo_1 10 
#define silo_2 11 
#define valvulaL2 29 
#define contraLavagem 27 
#define segundosUmaSemana 604800 
#define TEMPO_OCIOSO 300 
#define pinoInterruptTanque 0 // corresponde ao pino 2 
#define pinoInterruptSilo 1  // corresponde ao pino 3 
#define pinoInterruptInjec 2 // corresponde ao pino 4 
#define pinoSensorTanque 6 
#define pinoSensorSilo 5 
#define pinoSensorInjec 8  
#define boiaInferior 7 
#define boiaSuperior 9 
#define VOLUME_PURGA 100 // em Litros 


#define ULTIMA_MENSAGEM "Ultima.msg" 
#define SILOS_PRODUTOS "Silos.cfg" 
#define PROGRAMACAO "Ferti.cal" 
#define CONFIGURACAO "Start.cfg" 
#define RETROLAVAGEM "Retrolavagem.cal" 
#define DADOS "AutoCamp.nfo" 
#define LOG "AutoCamp.log" 
#define BACKUP "Backup.log" 

namespace AutoCampLib { 

    class Mensageiro 
    { 
     public: 
      Mensageiro(); 
      void lerSerial(); 
      void enviar1099(); 

     private: 
      bool guardarMensagem(char mensagem[]); 
      bool tratarMensagem(); 
      void tratar2001(); 
      void tratar2002(); 
      void tratar2003(); 
      void tratar2101(); 
      void tratar2901(); 
      void tratar2902(); 
      void tratar2903(); 
      void tratar2904(); 
      void tratar2905(); 
      void tratar2999(); 
      void enviar1001(); 
      void enviar1002(); 
      void enviar1003(); 
      void enviar1004(); 
      void enviar1005(); 
      void lerArquivo(String nome); 
      void escreverArquivo(String nome, int identificacao); 
      bool verificaLetra(char caracter); 
    }; 

    class Registrador 
    { 
     public: 
      static void debug(char mensagem[]); 
      static void info(char mensagem[]); 
      static void warn(char mensagem[]); 
      static void error(char mensagem[]); 

     private: 
      static void escreverRegistro(char mensagem[],char tipo[]); 
      static void verificarTamanho(); 
      static String buscarDataHora(); 
    }; 

    class Fertilizantes 
    { 
     public : 
      void setSilo(char *s); 
      void setVol(float volumeFert); 
      char *getSilo(); 
      float getVol(); 
      void setPortaSilo(int portasilo); 
      int getPortaSilo(); 


     private : 
      char _silo[8]; 
      float volumeF; 
      int _portasilo; 
    }; 

    class Eventos 
    { 
     public : 
      Eventos(); 
      void setSetor(int setor); 
      void setDuracao(int duracao); 
      void setSequencial(int sequencial); 
      void setVolumeH2O(float volumeAgua); 
      void setPorta(int porta); 
      int getPorta(); 
      int getSetor(); 
      int getDuracao(); 
      int getSequencial(); 
      float getVolumeH2O(); 
      //void setFertilizantes(LinkedList<Fertilizantes*>); 
      //LinkedList<Fertilizantes*> getFertilizantes(); 
      Fertilizantes* getFertilizante(int posicao); 
      void addFertilizante(Fertilizantes* fertilizante); 
      int sizeFertilizantes(); 



     private : 
      int _setor; 
      int _porta; 
      float _duracao; 
      int _sequencial; 
      float _volumeH2O; 
      LinkedList<Fertilizantes*> _fertilizantes; 
    }; 

    class Agendamentos 
    { 
     public: 
      Agendamentos(); 
      void setDia(int dia); 
      void setHora(int hora); 
      void setMinuto(int minuto); 
      void setSegundo(int segundo); 
      int getDia(); 
      int getHora(); 
      int getMinuto(); 
      int getSegundo(); 
      //LinkedList<Eventos*> getEventos(); 
      Eventos* getEvento(int posicao); 
      void addEvento(Eventos* evento); 
      int sizeEventos(); 

     private : 
      int _dia; 
      int _hora; 
      int _minuto; 
      int _segundo; 
      int posicao; 
      LinkedList<Eventos*> _eventos; 
    }; 

    class Start 
    { 

     public : 
      void setPressurizacao (int pressurizacao); 
      void setTroca (int troca); 
      void setInjecao(int injecao); 
      void setAtraso(int atraso); 
      void setOrdem(int ordem); 
      void setBase(float base); 
      void setTopo(float topo); 
      void setAltura(float altura); 
      void setSiloSTART(char *p); 
      void setPino(int pino); 
      void openReadStart(Start *start); 
      void leCaracter(char c, File file); 

      int getPressurizacao(); 
      int getTroca(); 
      int getInjecao(); 
      int getAtraso(); 
      int getOrdem(); 
      float getBase(); 
      float getTopo(); 
      float getAltura(); 
      char *getSiloSTART(); 
      int getPino(); 

     private : 
      Start *start; 
      File startcfg; 
      int pr; 
      int troca; 
      int inj; 
      int atraso; 
      int seq; 
      int pino; 
      float base; 
      float topo; 
      float altura; 
      char charLido; 

      int _pressurizacao; 
      int _troca; 
      int _injecao; 
      int _atraso; 
      int _ordem; 
      float _base; 
      float _topo; 
      float _altura; 
      char _silostart[8]; 
      int _pino; 
    }; 


    class Util 
    { 

     public : 
      static double calculaVolume(byte sensorInterrupt,byte sensorPin, float volumeDesejado); 
      static void contadorPulso(); 

    }; 


    class SensorNivel: public Thread 
    { 
     public : bool shouldRun(long time); 
       void run(); 

     private : int estado;  
    }; 


    class Programas: public Thread 
    { 
     public : bool shouldRun(long time); 
        void run(); 

     private : unsigned long tempo; 
        DateTime now ; 
    }; 

    class RecuperaIrriga: public Thread 
    { 
     public : 
       bool shouldRun(long time); 
       void run(); 
       void fecharTodoSetor(); 
       void verificarSetores(int numSetor); 

     private : long horaFim; 
        long horaAtual; 
        long horaAgendamento; 
        int numeroEvento; 
        DateTime now; 
        Agendamentos *agendamento; 

    }; 


    class VolumeAgua: public Thread 
    { 
     public : 
        bool shouldRun(long time); 
        void run(); 
        static void contadorPulso(); 
        double calculaVolume(byte sensorInterrupt,byte sensorPin, float volumeDesejado); 

     private : volatile byte contaPulso; 
        int numeroFert; 
        int numeroEvento; 
        float taxaFluxo; 
        float fatorCalibrador; 
        unsigned int fluxoL; 
        unsigned long totalL; 
        unsigned long oldTime; 
    }; 

    class VolumeSilo: public Thread 
    { 
     public : 
        bool shouldRun(long time); 
        void run(); 

        static void contadorPulso(); 
        double calculaVolume(byte sensorInterrupt,byte sensorPin, float volumeDesejado); 

     private : float fatorCalibrador; 
        volatile byte contaPulso; 
        int numeroEvento; 
        int numeroFert;  
        float taxaFluxo; 
        unsigned int fluxoL; 
        unsigned long totalL; 
        unsigned long oldTime;  
    }; 


    class RecuperaFerti: public Thread 
    { 
     public : 
        void verificarSetores(int numSetor); 
        void run(); 
        bool shouldRun(long time); 


     private : long horaAtual; 
        long inicio; 
        int encherTanque; 
        long horaAgendamento; 
        int encherSilo; 
        int numeroFert; 
        int numeroEvento; 
        DateTime now; 
        Agendamentos *agendamento; 


    }; 

    class RecuperaSilos: public Thread 
    { 

     public : bool shouldRun(long time); 
        void run(); 

     private : int numeroFert; 
        int numeroEvento; 

    }; 

    class Injecao: public Thread 
    { 

     public : bool shouldRun(long time); 
       void run(); 


     private : int numeroFert; 
        int numeroEvento; 
        int estado; 
    };     

    class NivelInjec: public Thread 
    { 
     private : int estado; 

     public : bool shouldRun(long time); 
       void run(); 
    }; 

    class Purga: public Thread 
    { 
     public : void run(); 
        bool shouldRun(long time); 
        static void contadorPulso(); 
        double calculaVolume(byte sensorInterrupt,byte sensorPin, float volumeDesejado);  
    }; 


    class NivelPurga: public Thread 
    { 
     private : int estado; 
        DateTime now; 
        int numeroEvento; 
        long horaAtual; 
        long horaAgendamento; 
        Agendamentos *agendamento; 

     public : bool shouldRun(long time); 
       void run(); 
       fecharTodoSetor(); 
    }; 





} 

using namespace AutoCampLib; 
#endif 
+2

이것은 'registrador_nivel'의 컴파일 된 코드를 찾을 수 없음을 의미합니다. 링커는'registrador_nivel' 코드가 들어있는 파일을 컴파일 할 때 생성되는 오브젝트 파일 ('.o' 파일)을 찾을 수 있어야합니다. 더 많은 설명을 원하십니까? –

+0

예하시기 바랍니다 !! .cpp가 필요합니까? – Rezik

+0

음, * 코드가 너무 많아서 문제를 해결하기 위해해야 ​​할 일을 정확하게 말할 수는 없습니다. 다음 번에 [최소, 완전하고 검증 가능한 예제] (http://stackoverflow.com/help/mcve)를 만들어야합니다. 그러나 왜 그런 종류의 오류가 발생했는지 설명 할 수있는 답을 쓸 수 있습니다. –

답변

1

링커 문제가

이 오류는 registrador_nivel이 어딘가에 존재하지만 링커가 어디에서 찾을 수 없다는 것을 의미합니다. 코드가 너무 많아서이있어 문제가 무엇인지 정확히 말할 수 없습니다.

방금 ​​가져온 오류가 발생하는 예를 보여 드리겠습니다. 이제 나는 단지이 파일을 가정 해 봅시다 :

// main.cpp 
extern char registrador_nivel; 

int main() { 
    registrador_nivel = 2; 
} 

라인 extern char registrador_nivel; 어딘가에, 당신은 registrador_nivel라는 전역 변수를 가지고 컴파일러를 알려줍니다. 그러나 main.cppregistrador_nivel 인 곳을 지정하지 않습니다. 어딘가에 registrador_nivel가 존재한다고합니다.

라인 registrador_nivel = 2;registrador_nivel의 값을 변경하려고합니다. 당신은 아직도 을 모른다.registrador_nivel가 어디인가. 당신은 당신이 그것을 바꿔야한다는 것을 알고 있습니다.

컴파일 중에 오브젝트 파일 (main.o 파일)이 생성됩니다. main.cpp과 동일한 것을 포함하는 파일이지만 컴퓨터에서 이해할 수있는 형식입니다. 따라서 main.o은 여전히 ​​registrador_nivel이 어디인지 말하지 않습니다.

이제 main.o 파일에서 최종 실행 파일을 만들려고합니다. 링커는 registrador_nivel이 실제로 어디에 있는지 찾으려고합니다. 이를 위해 정적 라이브러리 (.lib.a 파일)와 다른 개체 파일 (.o 파일)을 찾습니다. 라이브러리 또는 오브젝트 파일에 registrador_nivel이있는 파일이 없다면 링커는 undefined reference to registrador_nivel 오류를 보냅니다.


일반적인 솔루션을 다시 한번

, 나는 당신이 당신의 문제를 해결하기 위해해야 ​​할 정확히 무엇을 말할 수 없다; 나는 단지 짐작할 수있다.

  1. 당신은 정적 라이브러리 (.lib 또는 .a 파일)을 사용하고 있습니까? 귀하의 코드에서 Bibliotecas에 대해 이야기 한 것을 볼 수 있겠지만 그게 문제입니다. 어쩌면 registrador_nivel이 라이브러리에 정의되어있을 수 있습니다. 이 경우이 라이브러리에 링크해야합니다. 튜토리얼을 따라 다니는 거지, 그렇지?당신의 튜토리얼은 아마도 어떤 라이브러리를 링크시킬 것인지 그리고 어떻게해야 하는지를 말해 줄 것입니다.

  2. 컴파일해야하는 파일을 모두 컴파일 했습니까? 그렇지 않다면 .o 파일이 누락되었을 수 있습니다. 즉, registrador_nivel은 링커에서 찾을 수 없습니다.

  3. 해야 할 모든 것을 컴파일하고 있어야하고 모든 정적 라이브러리와 연결해야한다면 registrador_nivel을 선언해야 할 수도 있습니다. 이 경우 registrador_nivel이라는 전역 변수를 선언 해보십시오.

+1

정말로 감사합니다. @Anthony D. 당신의 설명은 매력이었습니다. 3 번 솔루션이 제 경우 인 것 같습니다. 고마워요 – Rezik

+0

@Rezik 모든 것이 예상대로 작동합니까? 그것이 컴파일된다는 사실은 그것이 반드시 작동한다는 것을 의미하지는 않습니다. –

+0

예. 지금 컴파일 중입니다. 불행하게도이 프로젝트는 완전히 테스트되어야 더 큰 환경을 필요로합니다. 추가로 테스트 해본 결과, eletric painel의 문제를 해결하고 쓰레드를 구현해야하는데, 전에는이 작업을 해본 적이 없었습니다 ... 그 다음 과제는 하하입니다. @Anthony D. – Rezik

관련 문제