Hi,
I'm writing a C++ program that will run on an STM3210E-EVAL board and I'm having some problems using STL vectors. I'm wondering what I'm doing wrong. (Or if STL vectors are even supported.)
Here's a snippet:
#include <vector> . . . void func() { std::vector<int> temp; temp.push_back(5); }
When I try to run the debugger on my target, I end up somewhere in assembly land and never reach the beginning of my main() function. (I am not familiar with assembly so, I'm not quite sure where I am or how I got there.)
When I run in simulator mode, everything works fine. (I end up at the beginning of my main() function like I expect.)
It appears that whenever I make any command that increases the size of my vector, I get the same result. If I never insert into my vector or resize it, then the debugger brings me to the beginning of main(), like I'd expect.
The last time I saw something like this was when my heap was 0 and I tried newing something on the heap. If anyone has any ideas, I'd be grateful.
I'm required to write my program in C++ and though I'm not required to use vectors, I really would like to. (I also have a few ideas of how to implement it differently if it turns out that vectors don't work.)
Thanks,
from the keil cpp examples, both need retarget.c and serial.c for retargeting the I/O functions. I guess you have to initialize these I/O functions if you want to use STL in debug mode.
Interesting... Thanks!
Make sure your project includes the Retarget.c file. The following will then work.
It looks like it worked! Thanks for all the help.
Now... why does that fix my problem...?
Make sure your project includes the Retarget.c file. The following will then work. (find an example in the Keil directory, probably c:\keil\arm\startup)
#include <vector> int main(void) { std::vector<int> temp; int size = sizeof(temp); int i = 5; temp.push_back(i); while(1){} }
In your project options, "Debug" tab, are "load application at startup" and "run to main" checked?
Yes, both of them are checked.
If you can get it to work on an ARM / CORTEX board, I think he would like to know what you did to get it to work.
Yes, this is exactly what I would like to know.
Per and Tamir. Does the following work for you or do you get some sort of error?
Not any IO or anything special here. I believe the OP is stating that this DOES NOT WORK on his board. If you can get it to work on an ARM / CORTEX board, I think he would like to know what you did to get it to work.
http://www.keil.com/support/man/docs/armlib/armlib_cihdfbhe.htm
Are you doing something I/O related in your startup file?
Anybody - is it "normal" for IO functions to be invoked upon initialization of the C runtime library used by the RealView compiler? If not, what on earth is happening here?!
It does not sound good that your program does not include your main().
Oh, main() is still there. It just decided to remove some other portions of my code... (Not sure which parts though...)
Using STL will bring in a lot of extra code.
I absolutely agree. I've got space for the time being. Hopefully, the reusability of the code is worth the code bloat.
Using STL will bring in a lot of extra code. C++ can give a smaller program growth when you add one more feature to an existing program. But it tends to produce very large "hello world" applications compared to C programs. And huge "hello world" applications compared to assembler applications.
The second thing I notice, is that in the non-working version, it removed testvector.o from the image.
Correction, it removed more portions of testvector.o.
Did you check your RAM/ROM address ranges (in the "Target" tab)?
IROM1 Start is 0x8000000, Size 0x80000 IRAM1 Start is 0x20000000, Size 0xC000
It looks reasonable to me...
Have you (or somebody else - check in your project) re-implemented "__rt_lib_init()"?
No, no one has touched/rewritten __rt_lib_init.
In addition, try this: compare the map file of a functioning program (no STL) to the one having a reference to STL. What do you see?
The first thing I notice is that the non-working version is much larger (RO = 23020, RW = 17400) compared to the working version (R0 = 1516, RW = 17008).
The second thing I notice, is that in the non-working version, it removed testvector.o from the image. (Testvector.cpp is the file that contains my main() function.)
Both things don't look that great in my opinion...
View all questions in Keil forum