multiple definition of errors, when there AREN'T

Author
dlc@frii.com
Super Member
  • Total Posts : 370
  • Reward points : 0
  • Joined: 2006/03/03 10:49:45
  • Location: 0
  • Status: offline
2012/01/17 23:46:24 (permalink)
0

multiple definition of errors, when there AREN'T

I'm beat.  I'm using MPLAB X v1.0.  Imported projects from MPLAB 8 seem to work fine, I've been totally unable to get a project of my own to work.  If I #include "adc.h" in my adc.c file, I get "multiple definition" errors.  If I don't, I get "implicit declaration" errors.  What gives?

I've read a bunch of answers to this question here, and they all deal with defining things in .h files, I don't.  Here is example code, it will cause "multiple definition of" errors for both of the functions used.  I've done this for years, this is how I've done it for years, something in the IDE is wonky here (IMO).

adc.h
 
#ifndef ADC_H
#define ADC_H

//ADC channels number
#define ADC_VOLTAGE      ADC_VOLT_CHAN

// Reference voltage, mV
#define AVCC                3300

void ADCInit(void);
unsigned long ADCRead(void);

#endif


adc.c
 
#include "iomapping.h"
#include "adc.h"

/*****************************************************************************
* Function: ADCInit
*
* Preconditions: None.
******************************************************************************/
void ADCInit(void)
{
    AD1CON2 = 0;        //AVdd, AVss, int every conversion, MUXA only
    AD1CON3 = 0x1F05;           //31 Tad auto-sample, Tad = 5*Tcy

    AD1CON1 = 0x80E4;        //Turn on, auto sample start, auto-convert
    AD1CHS = ADC_VOLTAGE;

    TRISBbits.TRISB2 = 1;
    TRISBbits.TRISB3 = 1;

 }

/*****************************************************************************
* Function: ADCRead
*
* Preconditions: ADCInit must be called before.
*
******************************************************************************/
unsigned long ADCRead(void)
{
unsigned long Result;


    // Wait for conversion to complete
    while(!AD1CON1bits.DONE);
    Result = (long) ADC1BUF0;

    Result = (Result*AVCC)/1024;

}


Can someone please send me down the path of sanity in MPLAB X?

Thanks,
DLC
post edited by dlc@frii.com - 2012/01/17 23:48:06
#1

7 Replies Related Threads

    newfound
    Super Member
    • Total Posts : 1804
    • Reward points : 0
    • Joined: 2003/11/07 12:35:49
    • Status: offline
    Re:multiple definition of errors, when there AREN'T 2012/01/17 23:55:22 (permalink)
    0
    I just battled through something similar and I found after I quit MPLAB  X and started it again the problem went away. Not sure if that is going to help your at all but it might.
    #2
    dlc@frii.com
    Super Member
    • Total Posts : 370
    • Reward points : 0
    • Joined: 2006/03/03 10:49:45
    • Location: 0
    • Status: offline
    Re:multiple definition of errors, when there AREN'T 2012/01/18 13:35:03 (permalink)
    0
    newfound

    I just battled through something similar and I found after I quit MPLAB  X and started it again the problem went away. Not sure if that is going to help your at all but it might.


    I tried that and it didn't work.  However... (I posted this data before, but it seems to have vanished...)

    I went into the project properties and clicked on the c30gcc link and unselected the "have symbols in release code" or something like that, and tried it, and this time it built.  I then went back and re-selected the "symbols" in the release code and it still worked.  It appears that you need to kick the mechanism that creates the makefile sometimes to get it to wake up.

    Re-starting the IDE solved a problem with "no rule to make <blahblah.o> (from a .h file)" errors that I got.

    It seems MPLABX is a bit quirky in release 1.0.  After I get over losing several hours of work battling a nonsensical error condition I'm sure that I'll be please with MPLABX over all.  AFTER I get over my mad...

    Thanks,
    DLC


    #3
    dlc@frii.com
    Super Member
    • Total Posts : 370
    • Reward points : 0
    • Joined: 2006/03/03 10:49:45
    • Location: 0
    • Status: offline
    Re:multiple definition of errors, when there AREN'T 2012/01/19 12:04:25 (permalink)
    0
    dlc@frii.com

    newfound

    I just battled through something similar and I found after I quit MPLAB  X and started it again the problem went away. Not sure if that is going to help your at all but it might.


    I tried that and it didn't work.  However... (I posted this data before, but it seems to have vanished...)

    I went into the project properties and clicked on the c30gcc link and unselected the "have symbols in release code" or something like that, and tried it, and this time it built.  I then went back and re-selected the "symbols" in the release code and it still worked.  It appears that you need to kick the mechanism that creates the makefile sometimes to get it to wake up.

    Re-starting the IDE solved a problem with "no rule to make <blahblah.o> (from a .h file)" errors that I got.

    It seems MPLABX is a bit quirky in release 1.0.  After I get over losing several hours of work battling a nonsensical error condition I'm sure that I'll be please with MPLABX over all.  AFTER I get over my mad...

    Thanks,
    DLC


    update of update...
    It appears that often some combination of re-starting MPLABX and fiddling with the project preferences is required every time I make a major change to the code base (like adding a new file).  It seems like the makefile doesn't get updated.

    Does anyone know of a sure-fire way to make sure that the generated makefile gets updated when there are changes?  (Don't tell me to make my own makefile, that isn't why I use an IDE!)

    DLC
    #4
    Jose Diaz
    Administrator
    • Total Posts : 1672
    • Reward points : 0
    • Joined: 2010/06/23 11:10:56
    • Location: 0
    • Status: offline
    Re:multiple definition of errors, when there AREN'T 2012/01/23 11:25:23 (permalink)
    0
    DLC,
    I am not clear on what the error mode is. "If I #include "adc.h" in my adc.c file, I get "multiple definition" errors.  If I don't, I get "implicit declaration" errors.  What gives? "
    Where do you get these errors? In the output window when you make, or reported by the parser (red marks in editor).
    I'll like to reproduce this issue. I have the code you sent but I need to know which compiler (with version) and which device you are using. Or you can attach to this thread a small project showing the problem. Also which OS are you using?
    "Does anyone know of a sure-fire way to make sure that the generated makefile gets updated when there are changes?" If you go to the project properties dialog and you change anything, the nbproject/Makefile-default.mk (or nbproject/Makefile-$conf.mk is $conf is not default) will be created. You can erase that file, open the project properties and change something (which debugger for example), then hit OK. The file should be recreated.



    #5
    Guest
    Super Member
    • Total Posts : 80499
    • Reward points : 0
    • Joined: 2003/01/01 00:00:00
    • Location: 0
    • Status: online
    Re:multiple definition of errors, when there AREN'T 2012/02/11 15:35:57 (permalink)
    0
    The problem is that the linker command in the makefile lists the .o files twice. For me restarting and fiddling around works so far. 
    #6
    Volker
    Senior Member
    • Total Posts : 130
    • Reward points : 0
    • Joined: 2007/01/29 03:00:06
    • Location: Germany
    • Status: offline
    Re:multiple definition of errors, when there AREN'T 2012/02/12 06:14:12 (permalink)
    0
    One question: Where is the definition of ADC_VOLT_CHAN?
    #7
    Guest
    Super Member
    • Total Posts : 80499
    • Reward points : 0
    • Joined: 2003/01/01 00:00:00
    • Location: 0
    • Status: online
    Re:multiple definition of errors, when there AREN'T 2012/04/30 12:48:01 (permalink)
    0
    I just had a variation of this same problem too.  I had to take the header files out of the project and it was able to finally link.
    #8
    Jump to:
    © 2017 APG vNext Commercial Version 4.5