错误:: 0:错误:(499)未定义符号:

时间:2017-07-04 08:12:42

标签: pic undefined-symbol xc8

我正在尝试使用globalVar.h来使我的main.c更清洁和整理。 但是,我和我的同事无法理解或解决许多错误。

请一些人如此友好并给我一个提示我可能做错了什么?

我在PIC12F1572上使用MPLAB X IDE 3.60和MPLAB XC8。

// main.c

#include "mcc_generated_files/mcc.h"
#include "globalVar.h"

void SDiagnose(sd_state_t SD_STATE);

void main(void)
{
    // Initialize the device
    SYSTEM_Initialize();

    INTERRUPT_GlobalInterruptEnable();
    INTERRUPT_PeripheralInterruptEnable();

    while (1)
    {
        if (gFlag_SDAktiv)          // Selbstdiagnose wird alle 180 Sekunden aktiviert
        {
            switch(gCnt_SD)
            {
            case 180:
                SD_STATE = START;
                SDiagnose(SD_STATE);                     //SD-PIN auf LOW ziehen, Laden starten
                break;

            case 190:
                SD_STATE = STARTMESSEN;
                SDiagnose(SD_STATE);               //Messung des Wertes während des Ladens und der Rekuperation starten
                break;

            default:
                break;

            }
        }   
    }
}

void SDiagnose(sd_state_t SD_STATE)
{ 
    switch(SD_STATE) 
    {
        case START:
            PIN_SDIAGNOSE_SetDigitalOutput();
            PIN_SDIAGNOSE_SetLow();
            break;

        case STARTMESSEN: 
            ADC1_StartConversion();
            break;

        default:  
            break;      
    }
}
//globalVar.h

#include <xc.h> // include processor files - each processor file is guarded.  


#ifndef EXTERN
    #define EXTERN extern
#endif


typedef enum {START, STOP, STARTMESSEN, MESSEN1, MESSEN2, FREIGEBEN} 
        sd_state_t;



EXTERN volatile sd_state_t SD_STATE;

EXTERN volatile unsigned char gFlag_AdcReady = 0;

EXTERN volatile unsigned char gFlag_SDAktiv = 0;

EXTERN volatile unsigned char gCnt_SD = 0;



#ifdef  __cplusplus
extern "C" {
#endif /* __cplusplus */



#ifdef  __cplusplus
}
#endif /* __cplusplus */
//tmr1.c

#include <xc.h>
#include "tmr1.h"

#include "../globalVar.h"

// ...
// MCC-Generated standard code..
// ...

void TMR1_DefaultInterruptHandler(void){
    // add your TMR1 interrupt custom code
    // or set custom function using TMR1_SetInterruptHandler()

    gCnt_SD++;


    if (gCnt_SD == 180)
    {
        gFlag_SDAktiv = 1;
    }
#include <xc.h>
#include "adc1.h"
#include "mcc.h"

#include "../globalVar.h"

void ADC1_ISR(void)
{
    // Clear the ADC interrupt flag
    PIR1bits.ADIF = 0;

    gFlag_AdcReady = 1; // Flag setzen, AD-Wandlung abgeschlossen



}
CLEAN SUCCESSFUL (total time: 125ms)
make -f nbproject/Makefile-default.mk SUBPROJECTS= .build-conf
make[1]: Entering directory 'C:/Users/AS/Desktop/MPLAB_Projekte/MINIMAL_CO_Sensor_V04.X'
make  -f nbproject/Makefile-default.mk dist/default/production/MINIMAL_CO_Sensor_V04.X.production.hex
make[2]: Entering directory 'C:/Users/AS/Desktop/MPLAB_Projekte/MINIMAL_CO_Sensor_V04.X'
"C:\Program Files (x86)\Microchip\xc8\v1.42\bin\xc8.exe" --pass1  --chip=12F1572 -Q -G  --double=24 --float=24 --opt=+asm,+asmfile,-speed,+space,-debug,-local --addrqual=ignore --mode=free -P -N255 --warn=-3 --asmlist -DXPRJ_default=default  --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,-osccal,-resetbits,-download,-stackcall,+clib   --output=-mcof,+elf:multilocs --stack=compiled:auto:auto "--errformat=%f:%l: error: (%n) %s" "--warnformat=%f:%l: warning: (%n) %s" "--msgformat=%f:%l: advisory: (%n) %s"    -obuild/default/production/mcc_generated_files/mcc.p1  mcc_generated_files/mcc.c 
"C:\Program Files (x86)\Microchip\xc8\v1.42\bin\xc8.exe" --pass1  --chip=12F1572 -Q -G  --double=24 --float=24 --opt=+asm,+asmfile,-speed,+space,-debug,-local --addrqual=ignore --mode=free -P -N255 --warn=-3 --asmlist -DXPRJ_default=default  --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,-osccal,-resetbits,-download,-stackcall,+clib   --output=-mcof,+elf:multilocs --stack=compiled:auto:auto "--errformat=%f:%l: error: (%n) %s" "--warnformat=%f:%l: warning: (%n) %s" "--msgformat=%f:%l: advisory: (%n) %s"    -obuild/default/production/mcc_generated_files/interrupt_manager.p1  mcc_generated_files/interrupt_manager.c 
"C:\Program Files (x86)\Microchip\xc8\v1.42\bin\xc8.exe" --pass1  --chip=12F1572 -Q -G  --double=24 --float=24 --opt=+asm,+asmfile,-speed,+space,-debug,-local --addrqual=ignore --mode=free -P -N255 --warn=-3 --asmlist -DXPRJ_default=default  --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,-osccal,-resetbits,-download,-stackcall,+clib   --output=-mcof,+elf:multilocs --stack=compiled:auto:auto "--errformat=%f:%l: error: (%n) %s" "--warnformat=%f:%l: warning: (%n) %s" "--msgformat=%f:%l: advisory: (%n) %s"    -obuild/default/production/mcc_generated_files/pin_manager.p1  mcc_generated_files/pin_manager.c 
"C:\Program Files (x86)\Microchip\xc8\v1.42\bin\xc8.exe" --pass1  --chip=12F1572 -Q -G  --double=24 --float=24 --opt=+asm,+asmfile,-speed,+space,-debug,-local --addrqual=ignore --mode=free -P -N255 --warn=-3 --asmlist -DXPRJ_default=default  --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,-osccal,-resetbits,-download,-stackcall,+clib   --output=-mcof,+elf:multilocs --stack=compiled:auto:auto "--errformat=%f:%l: error: (%n) %s" "--warnformat=%f:%l: warning: (%n) %s" "--msgformat=%f:%l: advisory: (%n) %s"    -obuild/default/production/mcc_generated_files/tmr0.p1  mcc_generated_files/tmr0.c 
"C:\Program Files (x86)\Microchip\xc8\v1.42\bin\xc8.exe" --pass1  --chip=12F1572 -Q -G  --double=24 --float=24 --opt=+asm,+asmfile,-speed,+space,-debug,-local --addrqual=ignore --mode=free -P -N255 --warn=-3 --asmlist -DXPRJ_default=default  --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,-osccal,-resetbits,-download,-stackcall,+clib   --output=-mcof,+elf:multilocs --stack=compiled:auto:auto "--errformat=%f:%l: error: (%n) %s" "--warnformat=%f:%l: warning: (%n) %s" "--msgformat=%f:%l: advisory: (%n) %s"    -obuild/default/production/mcc_generated_files/tmr1.p1  mcc_generated_files/tmr1.c 
"C:\Program Files (x86)\Microchip\xc8\v1.42\bin\xc8.exe" --pass1  --chip=12F1572 -Q -G  --double=24 --float=24 --opt=+asm,+asmfile,-speed,+space,-debug,-local --addrqual=ignore --mode=free -P -N255 --warn=-3 --asmlist -DXPRJ_default=default  --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,-osccal,-resetbits,-download,-stackcall,+clib   --output=-mcof,+elf:multilocs --stack=compiled:auto:auto "--errformat=%f:%l: error: (%n) %s" "--warnformat=%f:%l: warning: (%n) %s" "--msgformat=%f:%l: advisory: (%n) %s"    -obuild/default/production/main.p1  main.c 
"C:\Program Files (x86)\Microchip\xc8\v1.42\bin\xc8.exe" --pass1  --chip=12F1572 -Q -G  --double=24 --float=24 --opt=+asm,+asmfile,-speed,+space,-debug,-local --addrqual=ignore --mode=free -P -N255 --warn=-3 --asmlist -DXPRJ_default=default  --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,-osccal,-resetbits,-download,-stackcall,+clib   --output=-mcof,+elf:multilocs --stack=compiled:auto:auto "--errformat=%f:%l: error: (%n) %s" "--warnformat=%f:%l: warning: (%n) %s" "--msgformat=%f:%l: advisory: (%n) %s"    -obuild/default/production/mcc_generated_files/adc1.p1  mcc_generated_files/adc1.c 
mcc_generated_files/../globalVar.h:17: warning: (339) initializer in extern declaration
mcc_generated_files/../globalVar.h:19: warning: (339) initializer in extern declaration
mcc_generated_files/../globalVar.h:21: warning: (339) initializer in extern declaration
globalVar.h:17: warning: (339) initializer in extern declaration
globalVar.h:19: warning: (339) initializer in extern declaration
mcc_generated_files/tmr1.c:87: warning: (373) implicit signed to unsigned conversion
globalVar.h:21: warning: (339) initializer in extern declaration
mcc_generated_files/tmr1.c:96: warning: (2030) a data pointer cannot be used to hold the address of a function
pointer to function with no arguments returning void -> pointer to void
mcc_generated_files/tmr1.c:118: warning: (373) implicit signed to unsigned conversion
mcc_generated_files/tmr1.c:179: warning: (2029) a function pointer cannot be used to hold the address of data
pointer to void -> pointer to function with no arguments returning void
mcc_generated_files/../globalVar.h:17: warning: (339) initializer in extern declaration
mcc_generated_files/../globalVar.h:19: warning: (339) initializer in extern declaration
mcc_generated_files/../globalVar.h:21: warning: (339) initializer in extern declaration
mcc_generated_files/adc1.c:113: warning: (373) implicit signed to unsigned conversion
mcc_generated_files/adc1.c:119: warning: (373) implicit signed to unsigned conversion
mcc_generated_files/adc1.c:140: warning: (373) implicit signed to unsigned conversion
mcc_generated_files/../globalVar.h:17: warning: (339) initializer in extern declaration
mcc_generated_files/../globalVar.h:19: warning: (339) initializer in extern declaration
mcc_generated_files/../globalVar.h:21: warning: (339) initializer in extern declaration
mcc_generated_files/tmr0.c:75: warning: (373) implicit signed to unsigned conversion
mcc_generated_files/tmr0.c:90: warning: (2030) a data pointer cannot be used to hold the address of a function
pointer to function with no arguments returning void -> pointer to void
mcc_generated_files/tmr0.c:133: warning: (2029) a function pointer cannot be used to hold the address of data
pointer to void -> pointer to function with no arguments returning void
"C:\Program Files (x86)\Microchip\xc8\v1.42\bin\xc8.exe"  --chip=12F1572 -G -mdist/default/production/MINIMAL_CO_Sensor_V04.X.production.map  --double=24 --float=24 --opt=+asm,+asmfile,-speed,+space,-debug,-local --addrqual=ignore --mode=free -P -N255 --warn=-3 --asmlist -DXPRJ_default=default  --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,-osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf:multilocs --stack=compiled:auto:auto "--errformat=%f:%l: error: (%n) %s" "--warnformat=%f:%l: warning: (%n) %s" "--msgformat=%f:%l: advisory: (%n) %s"      --memorysummary dist/default/production/memoryfile.xml -odist/default/production/MINIMAL_CO_Sensor_V04.X.production.elf  build/default/production/mcc_generated_files/adc1.p1 build/default/production/mcc_generated_files/mcc.p1 build/default/production/mcc_generated_files/pin_manager.p1 build/default/production/mcc_generated_files/interrupt_manager.p1 build/default/production/mcc_generated_files/tmr1.p1 build/default/production/mcc_generated_files/tmr0.p1 build/default/production/main.p1     
Microchip MPLAB XC8 C Compiler (Free Mode) V1.42
Build date: Apr 12 2017
Part Support Version: 1.42
Copyright (C) 2017 Microchip Technology Inc.
License type: Node Configuration

:: warning: (1273) Omniscient Code Generation not available in Free mode
mcc_generated_files/adc1.c:103: advisory: (1510) non-reentrant function "_ADC1_StartConversion" appears in multiple call graphs and has been duplicated by the compiler
mcc_generated_files/adc1.c:95: warning: (520) function "_ADC1_SelectChannel" is never called
mcc_generated_files/adc1.c:110: warning: (520) function "_ADC1_IsConversionDone" is never called
mcc_generated_files/adc1.c:116: warning: (520) function "_ADC1_GetConversionResult" is never called
mcc_generated_files/adc1.c:122: warning: (520) function "_ADC1_GetConversion" is never called
mcc_generated_files/pin_manager.c:89: warning: (520) function "_PIN_MANAGER_IOC" is never called
mcc_generated_files/tmr1.c:108: warning: (520) function "_TMR1_StopTimer" is never called
mcc_generated_files/tmr1.c:114: warning: (520) function "_TMR1_ReadTimer" is never called
mcc_generated_files/tmr1.c:123: warning: (520) function "_TMR1_WriteTimer" is never called
mcc_generated_files/tmr1.c:145: warning: (520) function "_TMR1_Reload" is never called
mcc_generated_files/tmr1.c:152: warning: (520) function "_TMR1_StartSinglePulseAcquisition" is never called
mcc_generated_files/tmr1.c:157: warning: (520) function "_TMR1_CheckGateValueStatus" is never called
mcc_generated_files/tmr0.c:94: warning: (520) function "_TMR0_ReadTimer" is never called
mcc_generated_files/tmr0.c:103: warning: (520) function "_TMR0_WriteTimer" is never called
mcc_generated_files/tmr0.c:109: warning: (520) function "_TMR0_Reload" is never called
Non line specific message:: warning: (2028) external declaration for identifier "_SD_STATE" doesn't indicate storage location
:0: error: (499) undefined symbol:
    _SD_STATE(dist/default/production\MINIMAL_CO_Sensor_V04.X.production.obj) 
(908) exit status = 1
nbproject/Makefile-default.mk:227: recipe for target 'dist/default/production/MINIMAL_CO_Sensor_V04.X.production.hex' failed
make[2]: Leaving directory 'C:/Users/AS/Desktop/MPLAB_Projekte/MINIMAL_CO_Sensor_V04.X'
nbproject/Makefile-default.mk:90: recipe for target '.build-conf' failed
make[1]: Leaving directory 'C:/Users/AS/Desktop/MPLAB_Projekte/MINIMAL_CO_Sensor_V04.X'
nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed
make[2]: *** [dist/default/production/MINIMAL_CO_Sensor_V04.X.production.hex] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2

BUILD FAILED (exit value 2, total time: 3s)

我希望,你能帮助我! 提前谢谢!

1 个答案:

答案 0 :(得分:0)

您在global.h中声明了4个外部变量

EXTERN volatile sd_state_t SD_STATE;
EXTERN volatile unsigned char gFlag_AdcReady;
EXTERN volatile unsigned char gFlag_SDAktiv; //  = 0;  The assign should go in .c
EXTERN volatile unsigned char gCnt_SD; // = 0;

您需要在其中一个.c模块中为这些变量分配空间。这也是初始值分配的地方。它们将在启动时自动设置为零。

volatile sd_state_t SD_STATE;
volatile unsigned char gFlag_AdcReady;
volatile unsigned char gFlag_SDAktiv;
volatile unsigned char gCnt_SD;