EmbeddedRelated.com
Forums
The 2024 Embedded Online Conference

Using C++ on LPC3128

Started by soren_t_hansen April 20, 2005

I'm trying to use C++ to write a program to a LPC2138, and so far it
was working ok. But when trying to make a virtual function the linker
reports the following error:

/src/Blinky.o(.gnu.linkonce.r._ZTI11CLEDControl+0x0): undefined
reference to `vtable for __cxxabiv1::__class_type_info'
/src/Blinky.o(.gnu.linkonce.r._ZTI7CBlinky+0x0): undefined reference
to `vtable for __cxxabiv1::__si_class_type_info'

I'm using the GNU ARM (3.4.3) toolchain to compile the program and for
the linker I use the following:

-T $(LD_SCRIPT_RAM) \
-Wl,-Map=".\bin\Ram\Blinky.map",-Ttext=0x40000000,-Tdata=0x40003000 \
--gc-sections -o .\RAM\Blinky.elf \
-nostartfiles -nodefaultlibs

I've tried to use the -lstdc++ option, but that resulted in another
error, regarding delete(void*)

Is it because you can't use virtual functions on ARM7 or is it an
error in the compiler or maybe my linker script?

Best Regards
Sen Hansen



An Engineer's Guide to the LPC2100 Series



Add compiler flag : -fno-rtti to disable runtime type information, and in linker script add subsection

*(.gnu.linkonce*) which is required in C++.

But when you use some global obiects ( as global variables ), you should also add subsection

*(SORT(.ctors)) and modify startup file to call all constructors ( before calling main() function).

Jaromir _________________________________________________________________
List sprawdzony skanerem poczty mks_vir ( http://www.mks.com.pl )


Sen

> I've tried to use the -lstdc++ option, but that resulted in another
> error, regarding delete(void*)

Do you use for all stages esp. link g++ ?

> Is it because you can't use virtual functions on ARM7 or is it an

It has for sure nothing to do with the CPU.

> error in the compiler or maybe my linker script?

Most likely a tool-misuse or linker script. Less likely wrong configured
gcc.
Very unlikely a error in the compiler.

--
42Bastian Schick




--- In lpc2000@lpc2..., 42Bastian Schick <bastian42@m...> wrote:
> Sen
>
> > I've tried to use the -lstdc++ option, but that resulted in another
> > error, regarding delete(void*)
>
> Do you use for all stages esp. link g++ ?

I've only used it for the linking.
I have to mention that this is my first experience with gcc (and also
g++ :o), therefore my makefile and compilation rutine is likely to be
a bit inacurate...

But since it's a gcc issue, I'll probably have to take the question to
another place.

Best Regards
Sen Hansen



Ok, you're free to do what you want, but I feel I must make a comment.

C++ uses more resources (RAM and flash) than the same thing done in C code.
C++ tends to need far more dynamic memory allocation/freeing. Something that
is typically not very well handled on small embedded systems.
C++ hides detail making it harder to debug on an embedded platform.

In short, C++ and small embedded systems don't mix very well. In over 20
years of embedded programming I have never found a compelling need for C++ on
smaller systems.

There is nothing theoretical preventing the use of C++ on ARM7 though. It
will all be stuff to do with your compiler settings, linking, and making sure
you provide all the runtime stuff that C++ needs.

On Wednesday 20 April 2005 19:56, soren_t_hansen wrote:
> I'm trying to use C++ to write a program to a LPC2138, and so far it
> was working ok. But when trying to make a virtual function the linker
> reports the following error:
>
> /src/Blinky.o(.gnu.linkonce.r._ZTI11CLEDControl+0x0): undefined
> reference to `vtable for __cxxabiv1::__class_type_info'
> /src/Blinky.o(.gnu.linkonce.r._ZTI7CBlinky+0x0): undefined reference
> to `vtable for __cxxabiv1::__si_class_type_info'
>
> I'm using the GNU ARM (3.4.3) toolchain to compile the program and for
> the linker I use the following:
>
> -T $(LD_SCRIPT_RAM) \
> -Wl,-Map=".\bin\Ram\Blinky.map",-Ttext=0x40000000,-Tdata=0x40003000 \
> --gc-sections -o .\RAM\Blinky.elf \
> -nostartfiles -nodefaultlibs
>
> I've tried to use the -lstdc++ option, but that resulted in another
> error, regarding delete(void*)
>
> Is it because you can't use virtual functions on ARM7 or is it an
> error in the compiler or maybe my linker script?
>
> Best Regards
> Sen Hansen >
> Yahoo! Groups Links >




The ARM7 is structured very nicely to handle C++. I have been
writing embedded applications in C++ now for 15 years on 80C188's,
Arms, etc. All with less than 512K of flash. My project now, using
the LPC2138 is also written in C++. I argue that I can write my code
as tight in C++ as the same written in C and maybe even save some
space. C++ allows, in a clean way, to apply CS principles in an
otherwise EE world. It is true, however, that you need to be an
expert in the language (not just the syntax, but the model) to be
effective. Then again, I take the same approach on all my tools.
Most arguments against using C++ in embedded systems are from people
with little understanding of the language or 20+ years of experience
having difficulty with change. An interesting note, each year at the
Embedded Systems Conference, I see a larger and larger portion of
the engineers using C++. The trend in UML, code analysis, etc is
pushing the envelope of C. Anyway, just my two cents.

--- In lpc2000@lpc2..., Charles Manning <manningc2@a...>
wrote:
> Ok, you're free to do what you want, but I feel I must make a
comment.
>
> C++ uses more resources (RAM and flash) than the same thing done
in C code.
> C++ tends to need far more dynamic memory allocation/freeing.
Something that
> is typically not very well handled on small embedded systems.
> C++ hides detail making it harder to debug on an embedded platform.
>
> In short, C++ and small embedded systems don't mix very well. In
over 20
> years of embedded programming I have never found a compelling need
for C++ on
> smaller systems.
>
> There is nothing theoretical preventing the use of C++ on ARM7
though. It
> will all be stuff to do with your compiler settings, linking, and
making sure
> you provide all the runtime stuff that C++ needs.
>
> On Wednesday 20 April 2005 19:56, soren_t_hansen wrote:
> > I'm trying to use C++ to write a program to a LPC2138, and so
far it
> > was working ok. But when trying to make a virtual function the
linker
> > reports the following error:
> >
> > /src/Blinky.o(.gnu.linkonce.r._ZTI11CLEDControl+0x0): undefined
> > reference to `vtable for __cxxabiv1::__class_type_info'
> > /src/Blinky.o(.gnu.linkonce.r._ZTI7CBlinky+0x0): undefined
reference
> > to `vtable for __cxxabiv1::__si_class_type_info'
> >
> > I'm using the GNU ARM (3.4.3) toolchain to compile the program
and for
> > the linker I use the following:
> >
> > -T $(LD_SCRIPT_RAM) \
> > -Wl,-Map=".\bin\Ram\Blinky.map",-Ttext=0x40000000,-
Tdata=0x40003000 \
> > --gc-sections -o .\RAM\Blinky.elf \
> > -nostartfiles -nodefaultlibs
> >
> > I've tried to use the -lstdc++ option, but that resulted in
another
> > error, regarding delete(void*)
> >
> > Is it because you can't use virtual functions on ARM7 or is it an
> > error in the compiler or maybe my linker script?
> >
> > Best Regards
> > Sen Hansen
> >
> >
> >
> >
> >
> >
> > Yahoo! Groups Links
> >
> >
> >



Hi All,
I am new in this field. Can any one tell me some web site where I can learn,
how to use C++ code for LPC series?

Regards,
Sandeep
The Netherlands

From: "tah2k" <tah2k@tah2...>
Reply-To: lpc2000@lpc2...
To: lpc2000@lpc2...
Subject: [lpc2000] Re: Using C++ on LPC3128
Date: Mon, 25 Apr 2005 16:44:36 -0000 The ARM7 is structured very nicely to handle C++. I have been
writing embedded applications in C++ now for 15 years on 80C188's,
Arms, etc. All with less than 512K of flash. My project now, using
the LPC2138 is also written in C++. I argue that I can write my code
as tight in C++ as the same written in C and maybe even save some
space. C++ allows, in a clean way, to apply CS principles in an
otherwise EE world. It is true, however, that you need to be an
expert in the language (not just the syntax, but the model) to be
effective. Then again, I take the same approach on all my tools.
Most arguments against using C++ in embedded systems are from people
with little understanding of the language or 20+ years of experience
having difficulty with change. An interesting note, each year at the
Embedded Systems Conference, I see a larger and larger portion of
the engineers using C++. The trend in UML, code analysis, etc is
pushing the envelope of C. Anyway, just my two cents.

--- In lpc2000@lpc2..., Charles Manning <manningc2@a...>
wrote:
> Ok, you're free to do what you want, but I feel I must make a
comment.
>
> C++ uses more resources (RAM and flash) than the same thing done
in C code.
> C++ tends to need far more dynamic memory allocation/freeing.
Something that
> is typically not very well handled on small embedded systems.
> C++ hides detail making it harder to debug on an embedded platform.
>
> In short, C++ and small embedded systems don't mix very well. In
over 20
> years of embedded programming I have never found a compelling need
for C++ on
> smaller systems.
>
> There is nothing theoretical preventing the use of C++ on ARM7
though. It
> will all be stuff to do with your compiler settings, linking, and
making sure
> you provide all the runtime stuff that C++ needs.
>
> On Wednesday 20 April 2005 19:56, soren_t_hansen wrote:
> > I'm trying to use C++ to write a program to a LPC2138, and so
far it
> > was working ok. But when trying to make a virtual function the
linker
> > reports the following error:
> >
> > /src/Blinky.o(.gnu.linkonce.r._ZTI11CLEDControl+0x0): undefined
> > reference to `vtable for __cxxabiv1::__class_type_info'
> > /src/Blinky.o(.gnu.linkonce.r._ZTI7CBlinky+0x0): undefined
reference
> > to `vtable for __cxxabiv1::__si_class_type_info'
> >
> > I'm using the GNU ARM (3.4.3) toolchain to compile the program
and for
> > the linker I use the following:
> >
> > -T $(LD_SCRIPT_RAM) \
> > -Wl,-Map=".\bin\Ram\Blinky.map",-Ttext=0x40000000,-
Tdata=0x40003000 \
> > --gc-sections -o .\RAM\Blinky.elf \
> > -nostartfiles -nodefaultlibs
> >
> > I've tried to use the -lstdc++ option, but that resulted in
another
> > error, regarding delete(void*)
> >
> > Is it because you can't use virtual functions on ARM7 or is it an
> > error in the compiler or maybe my linker script?
> >
> > Best Regards
> > Sen Hansen
> >
> >
> >
> >
> >
> >
> > Yahoo! Groups Links
> >
> >
> >

_________________________________________________________________
Talk with your online friends with MSN Messenger http://messenger.msn.nl/



The 2024 Embedded Online Conference