c++ - Conflict of include files from an Arduino library -


i'm writing arduino libraries , have folder structure follows:

libraries      +foo     -foo.h     -helper.h      +bar     -bar.h     -helper.h      +helper     -helper.h 

foo , bar libraries created. reasoning behind putting helper.h in folders that, end user have easier time getting libraries work. also, libraries can configured having source code edited.

however, if write #include <helper.h> in sketch, it'll impossible control "helper.h" i'm including.

is there way hide helper.h foo , bar sketches?

the obvious answer is: don't write #include <helper.h>. files aren't part of implementation, , should included using #include "helper.h". if this, first place compiler include file in directory containing file including it: if include foo/foo.h, compiler pick foo/helper.h; if include bar/bar.h, compiler pick bar/helper' , on.

client code should set include path root, , things #include "foo/foo.h"; if necessary, can #include "foo/helper.h".

the 1 thing have strategy ensure uniqueness of of header guards. if application, sufficient mangle path include guard, e.g. use foo_helper_h, instead of foo_h. alternatively (and use library third parties should use), generate random string include guard. (if open file named abc.h doesn't exist, editor automatically generates following boilerplate:

/********************************************************/ /*      file:       abc.h                               */ /*      author:     j. kanze                            */ /*      date:       02/05/2013                          */ /* ---------------------------------------------------- */  #ifndef abc_h_20130502o481mbxfzeazz4dgib7ic4q9 #define abc_h_20130502o481mbxfzeazz4dgib7ic4q9  #endif 

it's safe bet include guard here never conflict other. (and have along these lines anyway, in order copyright message in file.)


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -