cancel
Showing results for 
Search instead for 
Did you mean: 

When using Cppcheck, which preprocessor defines and include directories should I specify?

JE2
Associate II
I am developing in C++ using STM32CubeIDE on an STM32L476.
I’m trying to use Cppcheck to verify the quality of my code, but the analysis fails with errors and I can’t get it to run successfully.
I have specified all the defines and include directories that are set in CubeIDE.
When the CPU is specified, certain internally determined macros and include directories are required, and it appears the errors are occurring because those are missing.
I am using the following options.
  • CPU "Cortex-M4(0)"
  • Core "0"
  • Floating-point unit "FPv4-SP-D16"
  • Floating-point ABI "Hardware implementation (mfloat-abi=hard)"
  • Instruction set "Thumb2"
  • Runtime library "Reduced C, reduced C++ (--specs=nano.specs)"
  • Enable "Use float with printf from newlib-nano (-u _printf_float")

Toolchain is ""GNU Tools for STM32(13.3rel1)

I am using CubeIDE on Windows.
The installation directory is left at its default (C:\ST).
 
Which definitions and include directories should I add?
 
1 ACCEPTED SOLUTION

Accepted Solutions
JE2
Associate II

I finally managed to solve this problem on my own.
I checked the Predefined Macros using the GCC compile options “-v -dM -E”.
I was finally able to do it by adding the following.

Defines:
__cplusplus=201402L
__cpp_ref_qualifiers=200710L
__INTPTR_TYPE__=int
__INT32_TYPE__=long int
__GNUC__
__VFP_FP__
__IEEE_LITTLE_ENDIAN
and
my projct defines(like STM32L476xx, USE_FULL_LL_DRIVER, ...)


Include Paths:
C:/ST/STM32CubeIDE_1.18.1/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.13.3.rel1.win32_1.0.0.202411081344/tools/arm-none-eabi/include/newlib-nano/
C:/ST/STM32CubeIDE_1.18.1/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.13.3.rel1.win32_1.0.0.202411081344/tools/arm-none-eabi/include/c++/13.3.1/
C:/ST/STM32CubeIDE_1.18.1/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.13.3.rel1.win32_1.0.0.202411081344/tools/arm-none-eabi/include/c++/13.3.1/arm-none-eabi/thumb/v7e-m+fp/hard/
C:/ST/STM32CubeIDE_1.18.1/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.13.3.rel1.win32_1.0.0.202411081344/tools/arm-none-eabi/include/c++/13.3.1/backward/
C:/ST/STM32CubeIDE_1.18.1/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.13.3.rel1.win32_1.0.0.202411081344/tools/arm-none-eabi/include/
C:/ST/STM32CubeIDE_1.18.1/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.13.3.rel1.win32_1.0.0.202411081344/tools/lib/gcc/arm-none-eabi/13.3.1/include/
C:/ST/STM32CubeIDE_1.18.1/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.13.3.rel1.win32_1.0.0.202411081344/tools/lib/gcc/arm-none-eabi/13.3.1/include-fixed/
and
my projct paths(like ./include, ./sharelib, ...)

I hope this will be helpful for anyone who wants to do the same.

View solution in original post

3 REPLIES 3
TDK
Super User

The defines and include directories used during compilation are shown in project properties. Right click on the project to access project properties. You should match those. They are also shown during compilation on the console tab.

TDK_0-1771388881901.png

 

If you still run into errors, read those error messages and let that guide what you need to change.

If you feel a post has answered your question, please click "Accept as Solution".
JE2
Associate II
I have already added those.
I have added images of the CppCheck error.
Please look at those photos.
I have already added the following toolchain folders to include Paths.
  • C:\ST\STM32CubeIDE_1.18.1\STM32CubeIDE\plugins\com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.13.3.rel1.win32_1.0.0.202411081344\tools\arm-none-eabi\include\
  • C:\ST\STM32CubeIDE_1.18.1\STM32CubeIDE\plugins\com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.13.3.rel1.win32_1.0.0.202411081344\tools\arm-none-eabi\include\c++\13.3.1\
  • C:\ST\STM32CubeIDE_1.18.1\STM32CubeIDE\plugins\com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.13.3.rel1.win32_1.0.0.202411081344\tools\lib\gcc\arm-none-eabi\13.3.1\include\
These may be incorrect.
I searched for “c++config.h” and tried to add it to the include path, but there are multiple versions depending on the ARM toolchain version, and I wasn’t sure which one I should select.
 
Do you have any additional advice after looking at the images?
 
cppcheck_err_1.pngcppcheck_err_2.png
JE2
Associate II

I finally managed to solve this problem on my own.
I checked the Predefined Macros using the GCC compile options “-v -dM -E”.
I was finally able to do it by adding the following.

Defines:
__cplusplus=201402L
__cpp_ref_qualifiers=200710L
__INTPTR_TYPE__=int
__INT32_TYPE__=long int
__GNUC__
__VFP_FP__
__IEEE_LITTLE_ENDIAN
and
my projct defines(like STM32L476xx, USE_FULL_LL_DRIVER, ...)


Include Paths:
C:/ST/STM32CubeIDE_1.18.1/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.13.3.rel1.win32_1.0.0.202411081344/tools/arm-none-eabi/include/newlib-nano/
C:/ST/STM32CubeIDE_1.18.1/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.13.3.rel1.win32_1.0.0.202411081344/tools/arm-none-eabi/include/c++/13.3.1/
C:/ST/STM32CubeIDE_1.18.1/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.13.3.rel1.win32_1.0.0.202411081344/tools/arm-none-eabi/include/c++/13.3.1/arm-none-eabi/thumb/v7e-m+fp/hard/
C:/ST/STM32CubeIDE_1.18.1/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.13.3.rel1.win32_1.0.0.202411081344/tools/arm-none-eabi/include/c++/13.3.1/backward/
C:/ST/STM32CubeIDE_1.18.1/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.13.3.rel1.win32_1.0.0.202411081344/tools/arm-none-eabi/include/
C:/ST/STM32CubeIDE_1.18.1/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.13.3.rel1.win32_1.0.0.202411081344/tools/lib/gcc/arm-none-eabi/13.3.1/include/
C:/ST/STM32CubeIDE_1.18.1/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.13.3.rel1.win32_1.0.0.202411081344/tools/lib/gcc/arm-none-eabi/13.3.1/include-fixed/
and
my projct paths(like ./include, ./sharelib, ...)

I hope this will be helpful for anyone who wants to do the same.