Valkyrie Valkyrie - 1 month ago 5
C Question

Append version number to output file for C application in Eclipse

I have a version.h header file where I have the version of my application defined:

#define VERSION 0x0100


I would like to add it as a suffix to the output file. So instead of having myapp.elf I would like to have myapp_0100.elf. Is there a way to use symbols in the compilation options?

Answer

You can do the opposite. Define a variable in Eclipse and use it when compiling. Go to the Project Properties-> C/C++ Build -> Build variables

Define a new variable blah with value 0100. Then in the build settings, depending on your project type you can pass the -DVERSION=${blah} to the compiler. It will define the symbol called VERSION with the value given. Now in Project Properties-> C/C++ Build -> Setting choose the Build Artifact tab. In the artifact name you can set myapp_${blah}.elf. Again, if your project is non-CDT managed, you can pass this variable to the makefile in order it to process it instead.