c++ - Include string in file on compilation -


i work on team project using teensy , matlab, , avoid version differences (e.g 1 person loads teensy version a, , person using matlab has version b of code), i'd send version string on pairing.

however, want version string sit in shared file between matlab code , teensy, , every time program loaded teensy, have included on compilation constant.

sort of like:

const string version = "<included file content>"; 

the matlab on part can read @ runtime.

i thought of using file contents assignment variable name shared both teensy , matlab, prefer more elegant solution if such exists, 1 doesn't include executing code external file @ runtime.

one way have simple setup so:

version.inc:

"1.0.0rc1"; 

main.cpp:

const string version =  #include "version.inc"  ... 

note newline between = , #include in place keep compiler happy. also, if don't want include semicolon in .inc file, can this:

main.cpp:

const string version =  #include "version.inc" ; // put semicolon on newline, again keep compiler happy 


edit: instead of .inc file, can have file extension desire. it's taste


edit: if wanted to, omit quotes .inc file, lead messy code this:

version.inc:

stringify(     1.0.0rc1 ); 

main.cpp:

#define stringify(x) #x  const string version =  #include "version.inc" ... 


edit:

as @Ôrel pointed out, handle generation of version.h or similar in makefile. assuming you're running *nix system, try setup this:

makefile:

... # "1.0.0rc1"; > version.h echo \"`cat version.inc`\"\; > version.h ... 

version.inc:

1.0.0rc1 

main.cpp:

const string version =  #include "version.h" 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -