Safety-certified tools Tools for Automotive Applications C-STAT Static analysis C-RUN Runtime analysis Debugging and trace probes IAR Visual State
To build projects from the command line, you can use the IAR Command Line Build Utility, IarBuild.exe. A common question is how to pass preprocessor defines on the command line to IarBuild.exe?
The compiler arm\bin\iccarm.exe has a -D option, documented in
Help>C/C++ Development Guide.
If you want to compile a file, and define MYDEFINE, you would do:
iccarm.exe main.c -D MYDEFINE=1
However, there is no similar -D option to IarBuild.exe, so you cannot specify preprocessor defines from the command line in this way.
This alternative might be a good choice if you have a few product variants that need to be handled differently in your project, based on for example a PROD_TYPE preprocessor symbol. You can create different configurations with Project>Edit Configurations.
In this example, you can create new configurations of your project named ProdType1, ProdType2 and ProdType3 where you define PROD_TYPE differently in Project>Options>C/C++ Compiler>Preprocessor>Defined symbols.
After this, you can call IarBuild.exe with the following arguments, and the PROD_TYPE preprocessor symbol will be set accordingly:
IarBuild.exe project.ewp -build ProdType1
IarBuild.exe project.ewp -build ProdType2
IarBuild.exe project.ewp -build ProdType3
Instead of using configurations, this alternative might be a good choice if you have, for example, a version number variable that needs to be updated often. This solution uses custom argument variables and provides a -varfile option to IarBuild.exe.
Configure a custom argument variable ARGVAR_VER with Tools>Configure Custom Argument Variables.
Under Project>Options>C/C++ Compiler>Preprocessor>Defined symbols, define a symbol VERSION that uses the custom argument variable ARGVAR_VER, like this: VERSION=$ARGVAR_VER$
Call IarBuild.exe with the option -varfile pointing out the .custom_argvars file generated by the IDE:
IarBuild.exe test.ewp -make Debug -log all -varfile test.custom_argvars
The .custom_argvars file is an XML file that was generated in the workspace directory. You can edit this file with an external editor or using a script, making it possible to change the value of the VERSION preprocessor symbol automatically.
If you follow the instructions above, it is possible to pass preprocessor defines on the command line to IarBuild.exe.
All product names are trademarks or registered trademarks of their respective owners.