Question about C++ feature (cout)
Reinhard
Posts: 489
Hi, currently I test some C++ features.
I use the SimpleIDE Version 0.6.2. and have this code snippet
Get this build result
Can not copy the message from the Build Status window, so I reproduce it on command line, thats no diff.
Is it not planned to use cout on µC or do I something wrong or is it a bug ?
regards
Reinhard
I use the SimpleIDE Version 0.6.2. and have this code snippet
#include <vector> #include <string> #include <iostream> using namespace std; int main(void) { vector<unsigned char>v; // ok v.push_back(0xAA); // ok string s = "Hello"; // ok cout << s << endl; // Build failed here return 0; }
Get this build result
knoppix@Microknoppix:~/myC/propeller_chip/_propgcc/cpp_vector_test$ propeller-elf-c++ -o a.out -Os -mxmmc cpp_vector_test.c -s /home/knoppix/propgcc/bin/../lib/gcc/propeller-elf/4.6.1/../../../../propeller-elf/lib/xmmc/libstdc++.a(basic_file.o): In function `.LVL34': /home/steve/gcc/build/gcc/propeller-elf/xmmc/libstdc++-v3/src/basic_file.cc:219: undefined reference to `_fdopen' collect2: ld returned 1 exit status
Can not copy the message from the Build Status window, so I reproduce it on command line, thats no diff.
Is it not planned to use cout on µC or do I something wrong or is it a bug ?
regards
Reinhard
Comments
It is hard enough getting printf and co. in there.
Reinhard,
cout is supported in XMM/XMMC modes, so it's a bug. Feel free to file an issue on the PropGCC development website at http://code.google.com/p/propgcc/issues/list.
In the interim, you can work around this by including the following snippet of code somewhere (anywhere) in your program:
Note that I haven't analyzed what that particular call to fdopen does (I believe the file in question is actually gcc/libstdc++-v3/config/io/basic_file_stdio.cc in the PropGCC source), but I know you don't need it for simple cout operations. With the above work-around, if you do something thta needs it, you'll get the "Ooops" error on your console.
Also note that adding iostream to a program adds around 500K, this it takes your 100K program and blows it up to over 600K! This takes almost a full minute to upload to a C3.
There is a "tiny" library posted on another thread at http://forums.parallax.com/showthread.php?139312-Tiny-I-O-Big-memory-savings-for-LMM-programs-that-print-get-from-the-serial-terminal; this would reduce your memory footprint greatly if you just want to print simple objects using cout (and not generic file I/O to memory, other devices, etc.).
Note, however, that the library was designed for LMM mode and I never tested it in XMM modes. Your issue caused me to finally test it; it appears there are some bugs and it doesn't work in XMM mode - I'll try to get to these soon. Watch the forum for updates.
- Ted
A simple hello c++ cout program will work with board type C3 and -mxmm or -mxmm-split mode.
Unfortunately, -mxmmc model does not have enough data space in Propeller HUB RAM to run using cout.
Applications using the standard c++ library without cout and iostreams will run with -mxmmc programs.
You will need to use printf or some other console IO alternative of course.
I'll get some packages out soon. For binary users. Source builders can update and build now.
Thanks,
--Steve
Great! Hopefully we'll be able to add another ARM-like feature later :thumb: