cancel
Showing results for 
Search instead for 
Did you mean: 

Conversion of Atollic C project to STM32Cube IDE C++

The original project was compiled and maintained in Atollic 9.3.0 for a STM32F030C8. We are trying to add a vendor stack that is written in C++.

We began by adding the #include <new> to the main to insure the compiler could see the needed include paths.

arm-atollic-eabi-gcc -c ..\src\main.c -mthumb -mcpu=cortex-m0 -std=gnu11 -DHSI_VALUE=8000000 -DSTM32F030 -DUSE_STDPERIPH_DRIVER -I../src -I../Libraries/CMSIS/Include -I../Libraries/CMSIS/Device/ST/STM32F0xx/Include -I../Libraries/STM32F0xx_StdPeriph_Driver/inc -IC:\Program Files (x86)\Atollic\TrueSTUDIO for STM32 9.3.0\ARMTools\arm-atollic-eabi\include\c++\6.3.1 -IC:\Program Files (x86)\Atollic\TrueSTUDIO for STM32 9.3.0\ARMTools\arm-atollic-eabi\include\c++\6.3.1\arm-atollic-eabi\bits -Og -ffunction-sections -g -fstack-usage -Wall -Wfatal-errors -specs=nano.specs -o src\main.o 
In file included from ..\src\main.c:22:0:
C:\Program Files (x86)\Atollic\TrueSTUDIO for STM32 9.3.0\ARMTools\arm-atollic-eabi\include\c++\6.3.1/new:39:28: fatal error: bits/c++config.h: No such file or directory

 The new file has a includes of "bit/c++config.h" which is not present. So it seemed that Atollic needed to install the specific includes for g++. Because Atollic is out of date we created a C++ workspace in the Cube IDE(version 1.8.0) and imported the original into it. The new project seems to have all the need GNU C++ references.

0693W00000aHmK2QAK.jpgWe are still seeing issues finding the include <new>:

rm-none-eabi-gcc "../src/main.c" -mcpu=cortex-m0 -std=gnu11 -g3 -DHSI_VALUE=8000000 -DSTM32F030 -DUSE_STDPERIPH_DRIVER -c -I../src -I../Libraries/CMSIS/Include -I../Libraries/CMSIS/Device/ST/STM32F0xx/Include -I../Libraries/STM32F0xx_StdPeriph_Driver/inc -O0 -ffunction-sections -fdata-sections -Wall -fstack-usage -MMD -MP -MF"src/main.d" -MT"src/main.o" --specs=nano.specs -mfloat-abi=soft -mthumb -o "src/main.o"
../src/main.c:22:10: fatal error: new: No such file or directory
   22 | #include <new>

There must be something basic about the project/workspace configuration for a mixed C/C++ STM32 build. Anyone running a mixed C/C++ build in Cube IDE?

Any help is appreciated.

1 ACCEPTED SOLUTION

Accepted Solutions
Pavel A.
Evangelist III

> We began by adding the #include <new> to the main

This is already a mistake, unless the original project is pure c++ (and maybe even is so).

The "main", that's, main.c, in STM32 projects usually is pure C file, not C++, so cannot include C++ specific headers there, such as <new>.

If you have a C project: right click on the project and select "convert to C++".

But the main.c should better be left as C; move all C++ to your own files.

View solution in original post

3 REPLIES 3
Pavel A.
Evangelist III

> We began by adding the #include <new> to the main

This is already a mistake, unless the original project is pure c++ (and maybe even is so).

The "main", that's, main.c, in STM32 projects usually is pure C file, not C++, so cannot include C++ specific headers there, such as <new>.

If you have a C project: right click on the project and select "convert to C++".

But the main.c should better be left as C; move all C++ to your own files.

The original project is pure C but the new stack we need to use is pure C++. The project pull down has no convert to C++. If we move object creation calls to a .cpp file, what would be a good way to reference C++ objects from a main.c or any other C file?

0693W00000aHr9TQAS.jpg

We found that the first part of the problem was not using a "C" extern definition on the calling function in the interface .cpp file.

extern "C" uint8_t testCompile(void);

Once this definition was in place the main.c file could see the function. At this point the option to convert the project to C++ appeared. Once the conversion was complete the C++ compiler option appeared in the project settings and everything build correctly.