Avoiding full paths in the output file
Technical Note 59374
Architectures:
All
Component:
general
Updated:
12/12/2022 8:49 AM
Introduction
In many projects, full paths are not wanted in the output file.
Discussion
When the output file contains full paths, the build will be different if rebuilt at another location.
The typical reason for this problem is that the application uses the assert
macro, which in turn uses the __FILE__
preprocessor symbol. The macro __FILE__
expands to the full path of the current file.
Another reason for this problem is when building the debug configuration at another location.
Suggestions
- Avoid Assert
You can use conditional compilation to avoid assert messages. The fileinstallation_path\target\inc\c\assert.h
uses the following construction to avoid assert messages being built into the output file, which is generated in the release configuration:
#ifdef NDEBUG
#define assert(test) ((void)0)
- Exclude the path in macros
You can do this by using the following option in Project > Options > C/C++ Compiler > Extra Options:
--no_path_in_file_macros
- Building with debug information
Debug information uses full paths to refer to source files. To get deterministic output in this scenario, you need to build at the same location.
Conclusion
Use the suggestions in this technical note to avoid full paths in the output file.
There might be other reasons for differences in the output file. For more information, see technical note 221111.
All product names are trademarks or registered trademarks of their respective owners.