• AVR Freaks

Hot!multiple definition of

Author
nyholku
Junior Member
  • Total Posts : 120
  • Reward points : 0
  • Joined: 2008/04/30 05:13:58
  • Location: 0
  • Status: offline
2020/04/03 05:25:53 (permalink)
0

multiple definition of

Hi,
 
I've spent the better part of this day trying to resurrect my project that has been bit by bit rot.
 
I just move one source file to a different location in the file hierarchy and it has been downhill ever since.
 
Now I've recreate the project a couple of times and with the help "Add existing Items from Folders..." generat trial and error the project now finds all files and compiles but fails at link stage with "multiple definition" errors for functions that I define in my main.c but which are referenced from an other file. 

If I remove main.c from the project then I get 'undefined' errors for those same files.
 
Looking at the Makefiles it looks like main is linked twice but for the life of me I cannot figure out how to fix this.
 
Please somebody just end my misery... ;) 

Am I the only one who thinks that this aspect of MPLABX is miserable and totally unintuitive and vere prone and fragile, after years of using it I never get the feeling that I'm in charge and know what I'm doing. 

Even bad old Make and his ugly friends seem user friendly in that respect.
 
cheers Kusti
 
#1

9 Replies Related Threads

    andersm
    Super Member
    • Total Posts : 2796
    • Reward points : 0
    • Joined: 2012/10/07 14:57:44
    • Location: 0
    • Status: online
    Re: multiple definition of 2020/04/03 05:56:26 (permalink)
    +1 (1)
    Post the full error messages. I'm assuming you're not doing something dumb like #include "main.c", or have full function definitions in header files?
    #2
    nyholku
    Junior Member
    • Total Posts : 120
    • Reward points : 0
    • Joined: 2008/04/30 05:13:58
    • Location: 0
    • Status: offline
    Re: multiple definition of 2020/04/03 06:04:23 (permalink)
    0
    Yes, I'm pretty sure I did not do that kind of dumb thing.
     
    And this project has been compiling fine for the past 6 months working on it on and off.
     
    I guess I'm after answer to the question what is the canonical way of add/removing/relocation files into a project.
     
    One would think that this should be trivially simple. Add file to a project and it will be included in the compile and link and remove it would prevent it from taking part  in the build process.
     
    I cannot produce that error again because now (after trying again deleting everything and adding them back again I get a different error):

    LEAN SUCCESSFUL (total time: 52ms)
    make -f nbproject/Makefile-default.mk SUBPROJECTS= .build-conf
    make[1]: Entering directory '/Users/nyholku/ASLAC.X'
    make -f nbproject/Makefile-default.mk dist/default/production/ASLAC.X.production.
    make[2]: Entering directory '/Users/nyholku/ASLAC.X'
    "/Applications/microchip/xc8/v2.05/bin/xc8-cc" -mcpu=ATtiny1616 -Wl,-Map=dist/default/production/ASLAC.X.production.map -DXPRJ_default=default -Wl,--defsym=__MPLAB_BUILD=1 -mdfp="/Applications/microchip/mplabx/v5.05/packs/Atmel/ATtiny_DFP/1.3.222" -O1 -I"include" -I"utils/assembler" -I"utils" -I"examples/include" -I"config" -I"./." -I"../PMLIN" -mext=cci -gdwarf-3 -o dist/default/production/ASLAC.X.production.elf -o dist/default/production/ASLAC.X.production.elf -Wl,--start-group -Wl,-lm -Wl,--end-group
    /Applications/microchip/mplabx/v5.05/packs/Atmel/ATtiny_DFP/1.3.222/gcc/dev/attiny1616/avrxmega3/crtattiny1616.o:../../../../crt1/gcrt1.S:310: undefined reference to `main'
    nbproject/Makefile-default.mk:121: recipe for target 'dist/default/production/ASLAC.X.production.' failed
    make[2]: Leaving directory '/Users/nyholku/ASLAC.X'
    collect2: error: ld returned 1 exit status
    nbproject/Makefile-default.mk:90: recipe for target '.build-conf' failed
    make[2]: *** [dist/default/production/ASLAC.X.production.] Error 1
    make[1]: Leaving directory '/Users/nyholku/ASLAC.X'
    make[1]: *** [.build-conf] Error 2
    nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed
    make: *** [.build-impl] Error 2

    #3
    NKurzman
    A Guy on the Net
    • Total Posts : 18655
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: online
    Re: multiple definition of 2020/04/03 06:49:28 (permalink)
    +1 (1)
    It can’t find main()
    Are you sure the C file containing it is in the project.
    #4
    NKurzman
    A Guy on the Net
    • Total Posts : 18655
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: online
    Re: multiple definition of 2020/04/03 06:49:28 (permalink)
    0
    It can’t find main()
    Are you sure the C file containing it is in the project.
    #5
    andersm
    Super Member
    • Total Posts : 2796
    • Reward points : 0
    • Joined: 2012/10/07 14:57:44
    • Location: 0
    • Status: online
    Re: multiple definition of 2020/04/03 06:55:50 (permalink)
    +1 (1)
    The case where you remove main is pretty obvious, it's the duplicate definition one that's more interesting.
    #6
    nyholku
    Junior Member
    • Total Posts : 120
    • Reward points : 0
    • Joined: 2008/04/30 05:13:58
    • Location: 0
    • Status: offline
    Re: multiple definition of 2020/04/03 07:15:52 (permalink)
    0
    Yes, the duplicate definition was mystere, especially since it disappeared and was replaced with undef when I removed main.c from the project. This was totally repeatable.

    But I cannot repeat any of these problems now that I've once again recreated the project and now it compiles.

    An interesting side observation: when I last time re-created the program I thought I'd put the main.c and an other source file into a sub directory 'src' of the project directory. Then the IDE did not compile the main.c at all when I added that folder 'src' to the project. Only when I moved the main.c to the top level of the project did it compile.

    At the same time couple of supporting files totally outside of the project folder hierarchy that I similarly added to the project were included just fine.

    There is no rhymer or reason to how the automatic Makefile generation works. 
     
    #7
    NKurzman
    A Guy on the Net
    • Total Posts : 18655
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: online
    Re: multiple definition of 2020/04/03 09:59:28 (permalink)
    +1 (1)
    Then You are playing with files make sure you use "Build All"  Make is easily fooled.  It may think that a file does not need to be rebuilt.  But it really does.
    #8
    nyholku
    Junior Member
    • Total Posts : 120
    • Reward points : 0
    • Joined: 2008/04/30 05:13:58
    • Location: 0
    • Status: offline
    Re: multiple definition of 2020/04/03 22:31:04 (permalink)
    0
    Thanks, yeah, done that clean and build all. Never has helped when I've been in this situation.

    Now it compiles but I still don't know why it now suddley compiles and how this system works not to mention how to repair it next time it happens.
    #9
    RicksterPIC
    Starting Member
    • Total Posts : 24
    • Reward points : 0
    • Joined: 2015/01/11 03:04:37
    • Location: 0
    • Status: offline
    Re: multiple definition of 2020/05/05 19:11:49 (permalink)
    0
    If main.c gives you duplicate, and no main.c gives you no main, I’d be curious if main.c has two mains?
    Or could you be trying to compile/link in main.c twice?
     
    You don’t need to “remove” files to try things out.
    Right click on the file name and choose “deselect...”
    it will grey out the file and rebuild the make files.
     
    add it back by right clicking again.

    ~ RicksterPIC
    #10
    Jump to:
    © 2020 APG vNext Commercial Version 4.5