9

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.

Michel Keijzers
  • 15,025
  • 28
  • 93
  • 119

2 Answers2

2

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)

Colin
  • 3,394
  • 1
  • 21
  • 29
  • I tried it, nothing changed, however, it seemed that the entire file was not taken into account. I'm still checking how to fix this. So I have to postpone the acceptance until I'm sure the problem will be solved. – Michel Keijzers Mar 26 '18 at 18:49
  • I continued with the problem, but I cannot get it working, it still seems that the cpp file is not taken into account. – Michel Keijzers Mar 26 '18 at 21:48
  • 1
    Is the cpp file being compiled. Add a `#error "testing"` to the top of it to see. – Colin Mar 27 '18 at 08:21
  • I made on purpose an error in the cpp file and the compiler missed the compilation in the file, since the linker gave the same error. Hopefully a reinstall will work (of the entire Eclipse environment). – Michel Keijzers Mar 27 '18 at 08:45
  • I gave the bounty to you, although it didn't solve the problem. I will update my question accordingly. – Michel Keijzers Apr 02 '18 at 17:59
1

Please follow below steps:-

  1. Better convert all the .c file to .cpp manually
  2. Check each header file and change macro which is specific to C language
  3. change the main function from C type to C++ (void main to int main()) also return a value from your main function.
  4. If you are using a make file check if specific C dependencies are referred and change them.

Hope this will help.

Abhijit Pritam Dutta
  • 5,521
  • 2
  • 11
  • 17