Have you ever wondered what the key icon appearing on a specific file or folder in the project explorer actually means? If you don't know what it means, it could indicate you are in trouble. The key icon indicates one or several build settings for the related file or folder differs from the project's overall build settings. If you have set specific build settings for the file or folder, then the key icon is just a friendly reminder so you do not forget this.
If you are not aware of specific build settings for the file or folder, then this could lead to frustration and problems as the project may not build or execute as intended. In this blog post, I will explain how to resolve these problems.
Setting individual build settings on a file or folder
First of all, let's illustrate what indivudial build settings for a file or folder means. In the Project explorer view, right-click on any file or folder in the tree. Click on Properties and browse to the C/C++ Build > Settings > Tool Settings tab. Any build setting changed in this GUI panel will now only apply to the selected context.
The context is the file or folder selected before choosing Properties as outlined above. In the screenshot below, you can see how the context is visualised in the dialog box title bar (the context is the file flash_if.c in this case):
Notice that the GUI looks slightly different when navigating to the tools settings for an individual file compared to when opening build settings for the entire project. Several tabs are not relevant for individual files or folders.
If, for example, the Optimization level is changed from -O0 to -O3, this change will only apply to flash_if.c in this case, and only for the selected build configuration (which is Debug in this example). Select All configurations if you also want to change the setting for the Release build configuration instead, or whatever build configuration is available in your project.
So, that is how a build setting can be applied to a single file or folder, which overrides the overall project build settings.
After leaving the configuration settings, the Project Explorer now shows the key icon on file_if.c - this highlights the fact this file is built using different build settings:
Now, what if the key icon is present on a file or folder which I have not deliberately/conciously modified the individual build settings for? Clearly, non-default build settings that may damage your build seems to apply.
Troubleshooting individual build settings
How do we find out the difference between the global project build settings, and the file or folder individual build settings, in case we don't think there should be any changes?
There are two ways (at least) of doing this. The first way is to manually inspect each node under the C Compiler in the Tool Settings tab vs the very same Tool Settings tab for the Build settings for the project in general (Project > Build Settings). This means jumping between two GUI windows which cannot be opened at the same time which makes this ... frustrating!
The second option is to search through the .cproject file. This is potentially much quicker. But potentially more dangerous. Don't manually edit the .cproject file since that could corrupt your project (build configurations). Instead only use this method to find the build setting which differs (read only).
The .cproject file is in the root of your project but not visibile from the Project Explorer view. Instead open the Navigator view. Or navigate to the project root folder in your file system. Open the .cproject in a simple text editor.
Search for the file or folder name which has the key icon. In this example search for flash_if.c. I get two hits:
<fileInfo id="com.atollic.truestudio.exe.debug.1521803907.1174558512" name="flash_if.c" rcbsApplicability="disable" resourcePath="src/flash_if.c" toolsToInvoke="com.atollic.truestudio.exe.debug.toolchain.gcc.417902881.469517682">
<tool id="com.atollic.truestudio.exe.debug.toolchain.gcc.417902881.469517682" name="C Compiler" superClass="com.atollic.truestudio.exe.debug.toolchain.gcc.417902881">
<option id="com.atollic.truestudio.exe.debug.toolchain.gcc.optimization.level.345315465" superClass="com.atollic.truestudio.exe.debug.toolchain.gcc.optimization.level" useByScannerDiscovery="false" value="com.atollic.truestudio.gcc.optimization.level.03" valueType="enumerated"/>
<inputType id="com.atollic.truestudio.gcc.input.2074618957" superClass="com.atollic.truestudio.gcc.input"/>
The .cproject file is not super-easy to read, but essentially we are able to find what specific settings are set for flash_if.c. The settings modified are for the C Compiler. The specific setting modified for the C Compiler is the Optimization level in this example, and its value is set to -O3.
So now we know what is changed. Don't modify this value in the .cproject file! Instead right-click on file_if.c in the Project Explorer view. Properties. Expand C/C++ Build > Settings > Tool Settings tab go to C Compiler > Optimization. Change the Optimization level here. And remember to apply it to all relevant build configurations.
Do you want to learn more on ARM Cortex-M development and debugging? Read this blog post: