This is the mail archive of the ecos-discuss@sourceware.org mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: eCos virtual functions


Your target.ld script probably needs to have a SECTIONS block defining the
output sections where the .text, .data, .bss, etc. input section go.  You
should take a look at the linker scripts that come with gcc and look at the
ld documentation.

The rest is C++ stuff and you should try posting on a C++ news group.  A
quick look at your code looks like you need some pure virtual functions in
your Abstract class and define Derived's destructor.  Try the following:

class Abstract {
protected:
    int a;
public:
    virtual void seta(int) = 0;
    virtual int geta() = 0;
    virtual ~Abstract() = 0;
};


class Derived : public Abstract {
    int a;
public:
    virtual void seta(int);
    virtual int geta();
    ~Derived();
};

Derived::~Derived()
{
}

void Derived::seta(int para)
{
    a=para;
}

int Derived::geta()
{
    return a;
}



-----Original Message-----
From: Ivan Kostov [mailto:ikostov@ira.uka.de] 
Sent: Sunday, July 15, 2007 8:06 AM
To: ecos-discuss@ecos.sourceware.org
Subject: eCos virtual functions

Hi everybody,
for our  project  we decided to use C++ code with virtual functions, but
when I try to compile code like this:

class Abstract {
protected:
    int a;
public:
    virtual void seta(int);
    virtual int geta();
    virtual ~Abstract();
};


class Derived : public Abstract {
public:
    virtual void seta(int);
    virtual int geta();
};

void Derived::seta(int para)
{
    a=para;
}

int Derived::geta()
{
    return a;
}

I get an error message from make:make

g++ -c -g -o main.o -I/home/kostov/syn-ecos/ecos_install//include -Wall
-Wpointer-arith -Winline -Wundef -g -O2 -ffunction-sections -fdata-sections
-fno-exceptions main.cpp
g++ -nostartfiles -L/home/kostov/syn-ecos/ecos_install//lib -Ttarget.ld
-g -nostdlib -Wl,--gc-sections -Wl,-static -g -o main main.o errors.o
`__gxx_personality_v0' referenced in section
`.gnu.linkonce.d.DW.ref.__gxx_personality_v0[DW.ref.__gxx_personality_v0]'
of /usr/lib/gcc/i586-suse-linux/4.0.2/../../../libsupc++.a(tinfo.o):
defined in discarded section `.text.__gxx_personality_v0' of
/usr/lib/gcc/i586-suse-linux/4.0.2/../../../libsupc++.a(eh_personality.o)col
lect2:
ld returned 1 exit status
make: *** [main] Error 1

I'm using synthetic target. I just changed the target.ld to:

MEMORY
{
    rom : ORIGIN = 0x00000000, LENGTH = 0x800000
    ram : ORIGIN = 0x02000000, LENGTH = 0x800000 }

When I try to compile this without any special options:

g++ -o main -I/home/kostov/syn-ecos/ecos_install/include
-L/home/kostov/syn-ecos/ecos_install/lib -Ttarget.ld -nostdlib main.cpp

I get the error message:

/tmp/ccaS3wuZ.o:(.gnu.linkonce.r._ZTI7Derived[typeinfo for
Derived]+0x8): undefined reference to `typeinfo for Abstract'
/tmp/ccaS3wuZ.o: In function `Derived::~Derived()':
main.cpp:(.gnu.linkonce.t._ZN7DerivedD1Ev[Derived::~Derived()]+0x18):
undefined reference to `Abstract::~Abstract()'
/tmp/ccaS3wuZ.o: In function `Derived::~Derived()':
main.cpp:(.gnu.linkonce.t._ZN7DerivedD0Ev[Derived::~Derived()]+0x18):
undefined reference to `Abstract::~Abstract()'
collect2: ld returned 1 exit status

I'm sorry if this is already discussed in the mailing list, but I am new to
eCos (yep, I have googled about "ecos virtual functions" anyway ;) ).
Thanks in advice to everybody.

Cheers,
Ivan Kostov



-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]