Avoiding full paths in the output file

Technical Note 59374

Arkitekturer:

All

Komponent:

general

Uppdaterad:

2022-12-12 08:49

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 file installation_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.

Det här innehållet finns tyvärr inte på svenska.

Vår webbplats finns främst på vårt koncernspråk engelska, förutom det innehåll för investerare som vi är lagstadgade att kommunicera på svenska. Vi rekommenderar att du besöker vår globala webbplats på engelska för att få en bättre upplevelse.

Vi stöder inte längre Internet Explorer. För att få bästa möjliga upplevelse av iar.com rekommenderar vi att du uppgraderar till en modern webbläsare som Chrome eller Edge.