/var/www/restricted/ssh/stm32/www/stm32circle/ STM CircleOS forum / Cannot link a C++ program with Ride7

Username:     
Password:     
             

Forum

# 1   2009-01-09 10:44:47 Cannot link a C++ program with Ride7

juser
New member
Registered: 2009-01-04
Posts: 3

Cannot link a C++ program with Ride7

I have Primer2. I made a Ride7 project for STM32F103VET6 and added two files -> one .c file and one .cpp file. The compilation is fine, but I get the following link errors:
undefined reference to `operator delete(void*)'
undefined reference to `operator new[](unsigned int)' 
undefined reference to `__cxa_end_cleanup'
undefined reference to `__gxx_personality_v0'
undefined reference to `vtable for __cxxabiv1::__si_class_type_info' 
undefined reference to `vtable for __cxxabiv1::__class_type_info'

The first two errors I'm able to fix by overloading the "new" and "delete" operators. This is probably, because the heap is not initialized. The other errors seems to be, because I have virtual functions and class destructors. When I comment all virtual functions (no VTABLE) and comment all dctors, then the application links correctly.
Does somebody know what options should be set in Ride7 for the C++ compiler and linker to work correctly? Maybe I need to link additional libraries?

Offline

 

# 2   2009-01-19 11:29:27 Cannot link a C++ program with Ride7

VincentC
Administrator
Registered: 2007-11-08
Posts: 149

Re: Cannot link a C++ program with Ride7

Hi,

Sorry for the late answer. I thought Francis would answer, and he thought I would.

The compiler is GCC, which is able to compile and link C++. But the Ride debugger and the STM32 libraries from ST only handle C, and we think it is a bad idea to use C++ on the STM32. (not enough RAM, ...)

So you can compile in C++, and you will be able to download and execute the resulting binary to the STM32 flash, but you will not be able to debug (no watch on classes or class members, erratic HLL-stepping in class functions, 32K debug limitation exceeded with the simplest C++ example if you don't have the PRO primer, etc.) nor to use the ST firmware libraries. (although this last point could probably be worked around quite easily, but not by us wink )

This is why in the default configuration, the linker is configured for pure C. I admit that the printing on the box can be quite ambiguous, and it is probably a printing mistake from us to have mentionned C++. I will let our commercial department elaborate on this in the other post you wrote.

Here is how to tell the linker to include the C++ libraries:
You have to add the "cclib" and "lstdc++" linker options to the link command-line:
ftp://www.raisonance.com/pub/forum/GCC_CPP/GCC_CPP.jpg

Note that the standard startup and linker script from Ride do initialize the heap. You only need to add the _sbrk function from syscalls.c. For this you can either include the "UART0 putchar" library (see the picture above), or take directly the code of the _sbrk function from this file:
C:\Program Files\Raisonance\Ride\Lib\ARM\io_putchar\syscalls.c
(but in this case you should remove the calls to _write and abort, as it will drag a lot of big and useless gcc things)

I hope it helps,

Vincent

Last edited by VincentC (2009-01-19 12:40:37)

Offline

 

# 3   2009-01-20 09:18:16 Cannot link a C++ program with Ride7

juser
New member
Registered: 2009-01-04
Posts: 3

Re: Cannot link a C++ program with Ride7

Thank you very much for your reply, which has been very helpful. 
I tried to link “libstdc++.a” by adding “-lstdc++” option, which resolved all missing symbols (that really great!).
The debugger does not work, because of an error “Code size limit exceeded!”. I had to set “Starter Kit limitation=No” to avoid another linker error -> “region FLASH overflowed by 1444 bytes”. Probably that error was caused, because the linker is trying to fit the whole program in 32KB.
My simple C++ program compiles and links properly. I’m not sure if it runs correctly, because I cannot use the debugger -> I’ll have to find some other way to trace, by using the display or the USB port and a PC.
The other option “-cclib” is recognized by the linker only when “Starter Kit limitation=No”. Could you please elaborate on what that option does?
Should I use the default linker script file? I see that you’re using different script “mycrt0.ld”.
Should I use the default startup file “$(RkitInst)lib\ARM\crt0_STM32x.o”?
I’ve read something about linking crtbegin.o and crtend.o, which call all global constructors/destructors. Should I link any additional object files?
It would be great if you include a STM32Primer2 C++ example -> something like “CPP toggle”. It would be much simpler to look at the project settings of a sample project, instead of playing with all the options.

Offline

 

# 4   2009-01-20 10:50:50 Cannot link a C++ program with Ride7

VincentC
Administrator
Registered: 2007-11-08
Posts: 149

Re: Cannot link a C++ program with Ride7

Hi,

For my test I used the default linker script: the 'script file' option is ignored when the 'Use default script file' option is set to 'Yes'. And also the default startup. But probably you should be using some modified versions if there are more things to initialize: Our default startup and script are made for pure C.

As I explained, the GCC compiler does support C++, but we (Raisonance, Ride, our debugger, our libraries, etc.) don't.
I compiled my first C++ program for ARM yesterday in order to answer your question, and for that I had to google for an answer in other forums. ;/
I think you should ask these precise questions about 'global constructor initialization' and such in the GCC forums, or rather you will probably find the answers there already. I don't know anything more than you on this.

You are limited to 32K debugging because you have a standard primer, not a PRO.
By unchecking the 'starter kit limitation' option, you tell the linker to allow links of more than 32K. But that will not affect debugging.

I don't understand what you mean by '“-cclib” is recognized by the linker only when “Starter Kit limitation=No”'. What error message do you get?
Anyways, the simplest C++ program exceeds 32K of code, so that means that you must uncheck this option whenever you use C++.

We will not make a C++ example project. At least not until our debugger supports C++. (and the ST firmware libraries for STM32)

Best Regards,

Vincent

Last edited by VincentC (2009-01-20 13:16:29)

Offline

 

Board footer