Search code examples
c++stm32truestudio

Atollic TrueSTUDIO: How to convert from C to C++?


I try to convert my project to C++ in TrueSTUDIO for STM32 by

  • Selecting project (in C/C++ Projects tab)
  • Right mouse button, select New/Other
  • In C/C++ tab, Convert to a C/C++ Project (Adds C/C++ Nature)
  • When pressing Next, nothing happens (unclear why)
  • When I press Next again, I see: Convert to a C/C++ project: The wizards adds C/C++ Nature to the selected projects to enable C/C++ Tools Supports for them
  • I press Finish

Than nothing happens, when I change main.c to main.cpp, I get the following error after build:

startup\startup_stm32f407xx.o: In function `LoopFillZerobss':
C:\Users\Michel\OneDrive\Stm32\Stm32CubeProjects\Fcb1010\Debug/..\startup/startup_stm32f407xx.s:115: undefined reference to `main'
collect2.exe: error: ld returned 1 exit status

It seems still C is used (also in the command line (first part):

arm-atollic-eabi-gcc -o Fcb1010.elf Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal.o Drivers\STM ...

I would expect g++ to be used.

How to change my settings/procedure to be able to use C++ within TrueSTUDIO for a CubeMX generated project?

UPDATE

I removed Atollic TrueStudio, removed AC6 System Workbench, and reinstalled AC6 System Workbench. Now I can use C++ at AC6 System Workbench, even using STL.

I do not dare to install Atollic TrueStudio again, since it breaks the existing installation of AC6 SystemWorkbench, probably because they both use Eclipse. A pity, since I liked some features of TrueStudio, but C++ is more important to me. So for me, no TrueStudio anymore.


Solution

  • The error you mention

    startup\startup_stm32f407xx.o: In function 'LoopFillZerobss': C:\Users\Michel\OneDrive\Stm32\Stm32CubeProjects\Fcb1010\Debug/..\startup/startup_stm32f407xx.s:115: undefined reference to `main' collect2.exe: error: ld returned 1 exit status

    Is a linker problem, I suspect the library is looking for a c main function. A C++ compiler performs name mangling, so the symbol will no longer be main.

    Try changing the signature of your main to extern "C" int main(void)