Two libraries, same enum definitions, how to prevent previous definition here

Hello,

I have created two libraries, both with similar functionality but controlling different devices. So I want both libraries to work independently of each other.

Library 1 example:
control1.h

#ifndef control1_h_
#define control1_h_
#include "control1_defines.h"

class control1class
{

};

#endif

control2.h

#ifndef control2_h_
#define control2_h_
#include "control2_defines.h"

class control2class
{

};

#endif

control1_defines.h

#ifndef control1_defines_h
#define control1_defines_h

enum someEnum
{
  foo = 0,
  bar = 1,
  foobie= 2
};

#endif

control2_defines.h

#ifndef control2_defines_h
#define control2_defines_h

enum someEnum
{
  foo = 0,
  bar = 1,
  foobie= 2
};

#endif

The error I get is something like,

In file included from control1.h:14:0, 

from myproject.ino:1: 

control_PCM5242/control1_defines.h:54:6: note: previous definition here

 enum someEnum

Any advice on how I can handle this issue? I don't want to have to rename all the enums to different ones, but I could if I have to. I thought that the classes would stay independent of eachother and therefore work...

Put the enum definitions inside the class definitions. Then access them via the scope resolution operator (double colon).

control1_defines.h

#ifndef control1_defines_h
#define control1_defines_h

#ifndef enum_defined
#define enum_defined

enum someEnum
{
  foo = 0,
  bar = 1,
  foobie= 2
};

#endif

#endif

control2_defines.h

#ifndef control2_defines_h
#define control2_defines_h

#ifndef enum_defined
#define enum_defined

enum someEnum
{
  foo = 0,
  bar = 1,
  foobie= 2
};

#endif

#endif

I have created two libraries, both with similar functionality but controlling different devices. So I want both libraries to work independently of each other.

As you created the two libraries then why not change one or both so that there is no clash ?

Put the enums in the .cpp file. Then only that set of classes can "see" it.

Its amazing what you can hide in a .cpp file.

-jim lee