[solved] Eclipse IDE: Multiple Definition of functions

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi folks,

I'm just starting to use Eclipse IDE with the AVR plugin. I've got a problem and I hope this is not the 'wrong' place to post it.

My project uses several source files: main.c, 3595_LCD.c, 3595_LCD.h box_game.c, box_game.h

I have had no problem compiling it with a make file I edit by hand. When I try to build it with Eclipse I get errors that every function from box_game.c is being defined multiple times but there are the appropriate prototypes in the header file. I have included box_game.h in both main.c and box_game.c

Console readout from build is below. Any idea where I'm going wrong on this one?

Thanks!

**** Build of configuration Release for project Tetris ****

make all 
Building file: ../box_game/box_game.c
Invoking: AVR Compiler
avr-gcc -Wall -Os -fpack-struct -fshort-enums -funsigned-char -funsigned-bitfields -std=gnu99 -mmcu=atmega168 -DF_CPU=8000000UL -MMD -MP -MF"box_game/box_game.d" -MT"box_game/box_game.d" -c -o"box_game/box_game.o" "../box_game/box_game.c"
Finished building: ../box_game/box_game.c
 
Building file: ../box_game/main.c
Invoking: AVR Compiler
avr-gcc -Wall -Os -fpack-struct -fshort-enums -funsigned-char -funsigned-bitfields -std=gnu99 -mmcu=atmega168 -DF_CPU=8000000UL -MMD -MP -MF"box_game/main.d" -MT"box_game/main.d" -c -o"box_game/main.o" "../box_game/main.c"
Finished building: ../box_game/main.c
 
Building target: Tetris.elf
Invoking: AVR C Linker
avr-gcc -Wl,-Map,Tetris.map -mmcu=atmega168 -o"Tetris.elf"  ./box_game/3595_LCD.o ./box_game/box_game.o ./box_game/main.o   
./box_game/main.o: In function `BOX_loc_return_bit':
main.c:(.text+0x0): multiple definition of `BOX_loc_return_bit'
./box_game/box_game.o:box_game.c:(.text+0x0): first defined here
./box_game/main.o: In function `BOX_loc_set_bit':
main.c:(.text+0x52): multiple definition of `BOX_loc_set_bit'
./box_game/box_game.o:box_game.c:(.text+0x52): first defined here
./box_game/main.o: In function `BOX_loc_clear_bit':
main.c:(.text+0xaa): multiple definition of `BOX_loc_clear_bit'
./box_game/box_game.o:box_game.c:(.text+0xaa): first defined here
./box_game/main.o: In function `BOX_store_loc':
main.c:(.text+0x104): multiple definition of `BOX_store_loc'
./box_game/box_game.o:box_game.c:(.text+0x104): first defined here
./box_game/main.o:(.bss+0x0): multiple definition of `BOX_piece'
./box_game/box_game.o:(.bss+0x0): first defined here
./box_game/main.o: In function `BOX_clear_loc':
main.c:(.text+0x1aa): multiple definition of `BOX_clear_loc'
./box_game/box_game.o:box_game.c:(.text+0x1aa): first defined here
./box_game/main.o: In function `BOX_load_reference':
main.c:(.text+0x250): multiple definition of `BOX_load_reference'
./box_game/box_game.o:box_game.c:(.text+0x250): first defined here
./box_game/main.o: In function `BOX_check':
main.c:(.text+0x282): multiple definition of `BOX_check'
./box_game/box_game.o:box_game.c:(.text+0x282): first defined here
./box_game/main.o: In function `BOX_pregame':
main.c:(.text+0x582): multiple definition of `BOX_pregame'
./box_game/box_game.o:box_game.c:(.text+0x482): first defined here
./box_game/main.o: In function `BOX_erase':
main.c:(.text+0x5ba): multiple definition of `BOX_erase'
./box_game/box_game.o:box_game.c:(.text+0x4ba): first defined here
./box_game/main.o: In function `BOX_clear_piece':
main.c:(.text+0x634): multiple definition of `BOX_clear_piece'
./box_game/box_game.o:box_game.c:(.text+0x534): first defined here
./box_game/main.o: In function `BOX_draw':
main.c:(.text+0x6d6): multiple definition of `BOX_draw'
./box_game/box_game.o:box_game.c:(.text+0x5d6): first defined here
./box_game/main.o: In function `BOX_rewrite_display':
main.c:(.text+0x756): multiple definition of `BOX_rewrite_display'
./box_game/box_game.o:box_game.c:(.text+0x656): first defined here
./box_game/main.o: In function `BOX_end_game':
main.c:(.text+0x7bc): multiple definition of `BOX_end_game'
./box_game/box_game.o:box_game.c:(.text+0x6bc): first defined here
./box_game/main.o: In function `BOX_line_check':
main.c:(.text+0x7e8): multiple definition of `BOX_line_check'
./box_game/box_game.o:box_game.c:(.text+0x6e8): first defined here
./box_game/main.o: In function `BOX_write_piece':
main.c:(.text+0x954): multiple definition of `BOX_write_piece'
./box_game/box_game.o:box_game.c:(.text+0x854): first defined here
./box_game/main.o: In function `BOX_rt':
main.c:(.text+0x9f6): multiple definition of `BOX_rt'
./box_game/box_game.o:box_game.c:(.text+0x8f6): first defined here
./box_game/main.o: In function `BOX_lt':
main.c:(.text+0xa1e): multiple definition of `BOX_lt'
./box_game/box_game.o:box_game.c:(.text+0x91e): first defined here
./box_game/main.o: In function `BOX_spawn':
main.c:(.text+0xa46): multiple definition of `BOX_spawn'
./box_game/box_game.o:box_game.c:(.text+0x946): first defined here
./box_game/main.o:(.bss+0x2): multiple definition of `cur_piece'
./box_game/box_game.o:(.bss+0x2): first defined here
./box_game/main.o:(.bss+0x3): multiple definition of `rotate'
./box_game/box_game.o:(.bss+0x3): first defined here
./box_game/main.o: In function `BOX_start_game':
main.c:(.text+0xb72): multiple definition of `BOX_start_game'
./box_game/box_game.o:box_game.c:(.text+0xa72): first defined here
./box_game/main.o: In function `BOX_up':
main.c:(.text+0xb8e): multiple definition of `BOX_up'
./box_game/box_game.o:box_game.c:(.text+0xa8e): first defined here
./box_game/main.o: In function `BOX_dn':
main.c:(.text+0xbb8): multiple definition of `BOX_dn'
./box_game/box_game.o:box_game.c:(.text+0xab8): first defined here
./box_game/main.o: In function `BOX_rotate':
main.c:(.text+0xbee): multiple definition of `BOX_rotate'
./box_game/box_game.o:box_game.c:(.text+0xaee): first defined here
make: *** [Tetris.elf] Error 1

edit: added [solved] to post title

Last Edited: Fri. Dec 12, 2008 - 04:40 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Silly question but you haven't got:

#include "box_game.c"

rather than:

#include "box_game.h"

within main.c have you?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Did you, by any chance, in main.c do

#include "BoxGame.c"

?

If so, get rid of it. You should never include one .c file into another. (There might be rare exceptions to this, but where you are right now they are not applicable, and the practice will only lead you into trouble).

The errors seems to indicate that the compiler saw implementations of all those variables or functions both when compiling main.c and when compiling box_game.c. When the linker tries to combine these two it has no clue as to which one implemen tation it should select (they are probably identical, but that is a special case - the linker will always spit if it sees two implementations of a function or a variable as in general they might be different).

I'm reluctant to talk about your problem in more specific terms until we get confirmation on if you actually did include one .c file into another .c file, as it is wated typing if this is not the case. Get back with confirmation (or not) on this, and we'll take it from there.

Let's hear from you!

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Indeed, I have included box_game.c in the main.c instead of the header file as intended.

Ones most foolish of errors are the most difficult to detect without outside help. Thanks for pointing out the obvious!