cancel
Showing results for 
Search instead for 
Did you mean: 

Suppress compiler warnings for library files

Scott_DeltaDev
Associate III

I'd like to configure GCC to suppress warnings from library files - e.g. I don't want to see the -Wconversion warning in stm32f4xx.h, but I do want to see all warnings from source files that I write myself.  I'm using STM32CubeIDE v1.10.1 on Windows.

I think a way to do this is adding a compiler flag to the MCU GCC Compiler->Miscellaneous->Other flags in project properties.  I've tried using the flags -isystem and -I, but haven't been able to suppress the warnings.

Thoughts on how to suppress warnings from all source files inside specific folders?

I'm aware of how to do this by adding #pragma to files I want to ignore warnings in, but I don't want to modify the library files.  I don't mind adding #pragma to custom source files if that's an option (i.e. globally disable warnings, selectively enable them in specific files), but I'd prefer to use compiler flags to ignore specific folders.

2 REPLIES 2
brokenagain
Associate II

Bump

 

Is there any update on this? CMSIS reports at ton of

warning: conversion to 'long unsigned int' from 'long int' may change the sign of the result [-Wsign-conversion]

 

Scott_DeltaDev
Associate III

To suppress warnings in the library code used in the STM32 project, we changed the way that library headers are included and added subfolder-level project property tweaks to some (though not all) of the subfolders in the project that serve as logical groupings for some of the library source files.

First, at the project properties level, right-click on the project and choose "Properties":

Scott_DeltaDev_0-1732295809308.png

 

Then, in C/C++ Build -> Tool Settings -> MCU GCC Compiler -> Include Paths, remove ../Middlewares/ST/touchgfx/framework/include and ../Drivers/STM32F4xx_HAL_Driver/Inc from the list of Include paths. Once that's done, re-include them by defining "-isystem" flags for those paths in the "Miscellaneous" node's "Other flags" list:

 

Scott_DeltaDev_1-1732295809298.png

 

The reason for this is that by including paths with "isystem" instead of just "i" implicitly tells the compiler to ignore all warnings generated by headers in those paths.

Once that's done, do the same thing under the "MCU G++ Compiler" node.

That takes care of warnings generated in the library header files, but additional steps are required to suppress warnings in the library source files. To do that, we'll take advantage of the fact that STM32CubeIDE supports subfolder-level properties independent of the parent project properties (and, for that matter, independent of the properties of any parent subfolders).

Most of the libraries in our project are grouped under the "Drivers" subfolder. Right-click on it and choose "Properties":

Scott_DeltaDev_2-1732295809253.png

 

Under C/C++ Build->Settings->MCU GCC Compiler->Miscellaneous, add "-Wno-unused-parameters" to the list of "other flags" to suppress the "unused variables" warning for all source files under the "Drivers" subfolder:

Scott_DeltaDev_3-1732295809282.png

 

Note that the two "-isystem" flags we added earlier were already automatically populated. However, also note that if we further change the parent project properties, those changes will no longer automatically propagate to the "Drivers" subfolder properties.

In other words, by defining special properties for the "Drivers" subfolder, we have in a sense unlinked it from changes to the project properties. Future changes (if any) to the project-level properties will need to be manually added to the "Drivers" subfolder.

Continue by going to the "Warnings" node and unchecking the warning options so as to match this screenshot: 

Scott_DeltaDev_4-1732295809362.png

 

Repeat the above two steps (adding the -Wno-unused-parameter flag and unchecking some of the warnings) for the "MCU G++ Compiler" node.

Now do the same for the TouchGFX subfolder.

Once that’s done, we need to drill down into the TouchGFX subfolder and reenable warnings on a tiny bit of application code buried therein. Go to TouchGFX -> gui -> src, right-click on "model", and choose "Properties":

Scott_DeltaDev_5-1732295809315.png

 

In those properties, undo the warning suppression meant for the library code by deleting the "-Wno-unused-variables" flags and re-checking the warnings that were disabled in the earlier "TouchGFX Properties" step:

Scott_DeltaDev_6-1732295809303.png

 

Scott_DeltaDev_7-1732295809291.png

 

Be sure to do the same for both the "MCU GCC Compiler" and "MCU G++ Compiler" nodes.

Now repeat all of that warning reenabling for the "screen_saver_screen", "screen_startup_screen", and "screen_status_screen" subfolders next to the "model" subfolder under TouchGX->gui->src

With that, the project should build without warnings on any of the library code.

If you ever want to revert the project so that the modified subfolders once again follow the project properties, the easiest way to do so is by opening the .cproject file for the project in a text editor and deleting the custom folder settings XML element (including all child elements). For example, to revert the "Drivers" subfolder to follow the project settings, delete this element and all of its child elements:

<folderInfo id="com.st.stm32cube.ide.mcu.gnu.managedbuild.config.exe.debug.338164076.588801503" name="/" resourcePath="Drivers">