1

I'm writing an embedded C application in Atmel Studio 6 for an AVR device. I'm not that good at "file hierarchy", but I've been doing my best. Also, thank you for taking the time to open this question.

Here is a file structure of the offending files:

enter image description here

So PLAYOP_FSM.C is a finite state machine that calls lower level functions. Some of the functions that it needs to call are implemented in BTN_INTERFACE.C; defined in BTN_INTERFACE.H

So both: PLAYOP_FSM.C and BTN_INTERFACE.C need to include the header file. Naturally, I put header guards to avoid multiple definitions.

However, I still get:

multiple definition of 'X'

where 'X' is actually my variables: u_yPos and u_xPos.

One of the other errors is:

first defined here

And then it puts a BTN_INTERFACE.O under file.

Here is a snapshot of the error list:

enter image description here

What have I done so far

I checked to make sure I made no "includes" in header files, I didn't accidentally include a ".c" file. I checked to make sure I didn't include BTN_INTERFACE.H anywhere else.

I can get it to compile if I take away the

#include BTN_INTERFACE.H

lines in my PLAYOP_FSM.C file. WHAT'S MORE, if I do that, the compiler does not complain about the function calls I make in PLAYOP_FSM.C, so no errors are thrown when I comment those out.

If I comment out the BTN_INTERFACE.C include lines, then as expected, I get errors concerning "not knowing what the dumb variables are".

Nick Williams
  • 253
  • 2
  • 12
  • 3
    The header file should contain *declarations* and not definitions. Header include guards only protects against multiple inclusion in a single [*translation unit*](http://en.wikipedia.org/wiki/Translation_unit_%28programming%29). – Some programmer dude Feb 20 '15 at 16:11
  • Ah, thank you for solving my headache; I'm such an idiot. The variables were being defined. – Nick Williams Feb 20 '15 at 16:29
  • "First defined here" is not another error, it is part of the same multiple declaration error, it is showing you *exactly* where the declaration was first encountered. You should post the raw error text rather than a screen-shot of the filtered window. – Clifford Feb 22 '15 at 08:56
  • Could you answer the question with your solution so we can take this off the unanswered queue? – Funkyguy Jul 01 '15 at 16:26

0 Answers0