C++ on uBlaze : C++ Problems...Possible Xilinx bugs ?

Hi all.

I'm using EDK 8.2.02i. ISE: 8.2.03i. Board: Spartan 3E Xilinx Starter Kit Rev.D

I'd like use C++ for my SW project but I have found problems...

1) Using namespace --------------- In my code application.h I have written:

namespace prova1{ int a=5; };

namespace prova2{ int a=10; int b=8; };

Then to make a test in my application.cc :

printf("prova1::a = %d \n", prova1::a); printf("prova2::a = %d \n", prova2::a); printf("prova2::b = %d \n", prova2::b);

So I expect to see in my terminal right values, but what really happen is:

prova1::a = 5 prova2::a = 5 prova2::b = 8

So system show and see only the first "a".

Moreover, and this is incredible, if in my makefile I compile using -0s optimization (size) then no error happen in linking. But if i DON'T USE ANY OPTIMIZATION this error occurs:

* *********************************************************************************** Creating target elf file... mb-g++ -Wl,-defsym -Wl,_TEXT_START_ADDR=0x22000C00

-o ./application.elf -Wall -g application.cc \ -I../microblaze_0/include/

-I../Libs/ \ -L../microblaze_0/lib/ -L../Libs/ -LD:\EDK/gnu/microblaze/nt/mi croblaze/lib -LD:\EDK/gnu/microblaze/nt/include/C++/3.4.1/ -lcommon -lstdc++ /cygdrive/c/DOCUME~1/alettoal/LOCALS~1/Temp/cc31lsQU.s: Assembler messages: /cygdrive/c/DOCUME~1/alettoal/LOCALS~1/Temp/cc31lsQU.s:102: Fatal error: Symbol a already defined. make: *** [application.elf] Error 1

* ***********************************************************************************

2) Using simple class ------------------

In my application.h :

class Cliente { public: char name[20]; char surname[20]; void p() { printf("Client::p\n"); } virtual void insert_name( void ) = 0; };

class ClienteD : public Cliente { public: void insert_name() { printf("insert_name ClientD\n"); } void p() { printf("ClientD::p\n"); } };

In my application.cc :

...

ClienteD pippo; ...

ClienteD* cliente = new ClienteD(); cliente->insert_name(); cliente->p();

Cliente* base = new ClienteD(); base->insert_name(); base->p();

pippo.p();

But when I see my terminal window NOTHING, NO any printf() Appear !

KEEP IN MIND that the SAME application (Example 2) only) I used for testing C++ with EDK 8.1.01i and all was fine ! Why now I have all these problem ?

Thanks in advance for any answers !

Cheers,

Al.

Reply to
Alfmyk
Loading thread data ...

prova2::a); printf("prova2::b = %d \n", prova2::b);

optimization (size) then no error happen in linking. But if i DON'T USE ANY OPTIMIZATION this error occurs:

*********************************************************************************** Creating target elf file... mb-g++ -Wl,-defsym -Wl,_TEXT_START_ADDR=0x22000C00

-o ./application.elf -Wall -g application.cc \ -I../microblaze_0/include/

-I../Libs/ \ -L../microblaze_0/lib/ -L../Libs/ -LD:\EDK/gnu/microblaze/nt/mi croblaze/lib -LD:\EDK/gnu/microblaze/nt/include/C++/3.4.1/ -lcommon -lstdc++ /cygdrive/c/DOCUME~1/alettoal/LOCALS~1/Temp/cc31lsQU.s: Assembler messages: /cygdrive/c/DOCUME~1/alettoal/LOCALS~1/Temp/cc31lsQU.s:102: Fatal error: Symbol a already defined. make: *** [application.elf] Error 1

***********************************************************************************

printf("Client::p\n"); } virtual void insert_name( void ) = 0; };

printf("insert_name ClientD\n"); } void p() { printf("ClientD::p\n"); } };

C++ with EDK 8.1.01i and all was fine ! Why now I have all these problem ?

This sounds more like a problem with the compiler than with the chip or processor implementation.

I suggest that if you don't already have a native PC gnu toolchain that you get one (use Cygwin if you're running windows), try your code out on that, and see what happens. If you get the same results then you'll know that it's an issue either with Gnu or you.

--

Tim Wescott
Wescott Design Services
http://www.wescottdesign.com

Posting from Google?  See http://cfaj.freeshell.org/google/

"Applied Control Theory for Embedded Systems" came out in April.
See details at http://www.wescottdesign.com/actfes/actfes.html
Reply to
Tim Wescott

Thanks for your answer Tim, anyway I have found problem: if you want to use C++ and also use the "new" keyword the system must have some HEAP memory to allocate your "new" instance of objects. Now in standard mode the compiler/linker use HEAP=0x0 (STACK=0x400) and so the program did crash with no HEAP instanced. In the compiling/linking option adding -Wl, defsym -Wl,_HEAP_SIZE=0x400 now I can use program with no problem at all. What is very strange is that with a previous version of EDK (8.1) this procedure was not necessary. Anyway I thimk is correct now. Moreovere what it is strange is that implementing an if (... = NULL) to check if the new instruction has been executed well (Ok pointer for the new object) nothing happen because system crash immediately after "new" instruction. Off course this happen if HEAP size is 0.

Cheers, Alfmyk

Reply to
Alfmyk

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.