virtual functions

Guest #1171319
Rate this post
• ▲ useful
▼ not useful
Hi:)

I would like to use virtual functions. I wrote simple test program:

/*********************************************************************** 
***/
#include "lpc2000.h"

class A {
  public:
  void virtual fun1(){
    GPIO_IOCLR |= (1<<21) ;
  }
};

class B : public A{
  public:
  void fun1(){
    GPIO_IOCLR |= (1<<20);
  }
  void fun3(){
    GPIO_IOCLR |= (1<<18);
  }
};

//new object
B sth ;

int main(){
  //main loop
  while(1){;}
}
/*********************************************************************** 
***/

but compliler returns error:

"C:\DOCUME~1\kuba\USTAWI~1\Temp/ccUDbaaa.o:(.rodata._ZTI1B[typeinfo for
B]+0x0): undefined reference to `vtable for
__cxxabiv1::__si_class_type_info'
C:\DOCUME~1\kuba\USTAWI~1\Temp/ccUDbaaa.o:(.rodata._ZTI1A[typeinfo for
A]+0x0): undefined reference to `vtable for
__cxxabiv1::__class_type_info'
collect2: ld returned 1 exit status
make.exe: *** [main.elf] Error 1"

What is going on or what is wrong ?
#1171320
Rate this post
• ▲ useful
▼ not useful
> What is going on or what is wrong ?

There is nothing intrinsically wrong with the code (although you should
consider including a virtual destructor in all virtual classes).

It is usually a good idea to post the entire compile log so we can see
how you are invoking the compiler/linker, and what if any other errors
occur.

Are you invoking the linker via the compiler, or calling the linker
separately? If so, are you using arm-elf-gcc or arm-elf-g++? You can use
gcc for C++ compilation, but if using gcc to launch the linker, it does
not automatically include the C++ library in the link (you need
-lstdc++). It does this automatically if you use g++.

Clifford
Guest #1171321
Rate this post
• ▲ useful
▼ not useful
Clifford Slocombe wrote:
>> What is going on or what is wrong ?
> It is usually a good idea to post the entire compile log so we can see
> how you are invoking the compiler/linker, and what if any other errors
> occur.
> Clifford

My compiler log looks like this:

-------- begin --------
arm-elf-gcc (GCC) 4.1.1 (WinARM)
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is
NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.


Linking: main.elf
arm-elf-gcc  -mcpu=arm7tdmi  -I. -DROM_RUN  -O3 -Wall -Wcast-align
-Wcast-qual -Wimplicit -lgcc -Wpointer-arith -Wswitch -Wredundant-decls
-Wreturn-type -Wshadow -Wunused -Wa,-adhlns=main.cpp   -MD -MP -MF
.dep/main.elf.d    main.cpp     --output main.elf -nostartfiles
-Wl,-Map=main.map,--cref -lc -lnewlib-lpc -lm -lc -lgcc
-Tbuild/LPC2103-ROM.ld
main.cpp:8: warning: 'class diody' has virtual functions but non-virtual
destructor
C:\DOCUME~1\kuba\USTAWI~1\Temp/ccw9baaa.o:(.rodata._ZTI5diody[typeinfo
for diody]+0x0): undefined reference to `vtable for
__cxxabiv1::__class_type_info'
collect2: ld returned 1 exit status
make.exe: *** [main.elf] Error 1

What I can do for compiling without errors? I need virtual functions for
happiness :)
Guest #1171322
Rate this post
• ▲ useful
▼ not useful
Ok, I have changed options in makefile from:
$(CC) $(THUMB) $(ALL_CFLAGS) $(AOBJARM) $(AOBJ) $(COBJARM) $(COBJ)
$(CPPOBJ) $(CPPOBJARM) --output $@ $(LDFLAGS)
to:
$(CPP) $(THUMB) $(ALL_CFLAGS) $(AOBJARM) $(AOBJ) $(COBJARM) $(COBJ)
$(CPPOBJ) $(CPPOBJARM) --output $@ $(LDFLAGS)

Now I have another problem, but solution is (probably) i two other
posts: "C++ and WinARM" and "Linker problems". I will try to solve my
problem with sugestions from this topics:)
Thx
Guest #1171323
Rate this post
• ▲ useful
▼ not useful
I was traying to use standard crt0.S file in my project, but compiler
show result:

-------- begin --------
arm-elf-gcc (GCC) 4.1.1 (WinARM)
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is
NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.


Linking: main.elf
arm-elf-g++  -mcpu=arm7tdmi  -I. -g -DROM_RUN  -Os -Wall -Wcast-align
-Wcast-qual -Wimplicit  -Wpointer-arith -Wswitch -Wredundant-decls
-Wreturn-type -Wshadow -Wunused -Wa,-adhlns=build/crt0.o   -MD -MP -MF
.dep/main.elf.d build/crt0.o    main.cpp     --output main.elf
-nostartfiles -Wl,-Map=main.map,--cref -lc -lnewlib-lpc -lm -lc -lgcc
-TLPC2103-ROM.ld
c:/winarm/bin/../lib/gcc/arm-elf/4.1.1/../../../../arm-elf/bin/ld.exe:bu 
ild/crt0.o:
file format not recognized; treating as linker script
c:/winarm/bin/../lib/gcc/arm-elf/4.1.1/../../../../arm-elf/bin/ld.exe:bu 
ild/crt0.o:1:
syntax error
collect2: ld returned 1 exit status
make.exe: *** [main.elf] Error 1

Why the file format is not recognized? Is it something wrong in makefile
? Maybe this file is incorrect? Why? :(
Guest #1171325
Rate this post
• ▲ useful
▼ not useful
Do you see an error-message when compiling the example
lpc2129_newlib_cpp from the example-collection that comes with WinARM? I
do not use C++ in my "real" developments but this example should
demonstrate virtual functions.

Martin Thomas

Reply

Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.

Formatting
  • [c]C-Code[/c]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]
  • [[Title]] – link to an article
  • Link to another post: right-click its post ID (#8078628), copy the address, paste it into the text

More about formatting

Post long source code as an attachment, not in the text.

Already registered? Log in

Not shown to anyone. We send you a link; your post appears once you confirm it there.

By submitting you create a free account and accept the terms of use.