Skip to content

Compilation error: conditional #include inside #if #4512

Closed
@e-moe

Description

@e-moe

Hi guys, I'm trying to implement one class for two different MCU types using conditional #include.
Is there any way to avoid error and specific files compilation (e.g. compile only a.cpp or b.cpp but not both of them)?

Arduino 1.6.7. Mac OS X El Capitan.

sketch/b.cpp.o: In function `I::test()':
sketch/b.cpp:3: multiple definition of `I::test()'
sketch/a.cpp.o:sketch/a.cpp:3: first defined here
collect2: error: ld returned 1 exit status
exit status 1
Error compiling.

sketch:

#if defined(__AVR_ATtiny85__)
  #include "a.h"
#else
  #include "b.h"
#endif

void setup() {
  I i = I();
  i.test();
}

void loop() {
}

a.h:

class I
{
  public:
  void test();
};

a.cpp

#include "a.h"

void I::test() {
  return; // specific code for MCU A
}

b.h:

class I
{
  public:
  void test();
};

b.cpp

#include "b.h"

void I::test() {
  return; // specific code for MCU B
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions