473,395 Members | 1,972 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Undefined symbols: vtable for Foo

r
I compile this on a Max OSX with
GCC version 1151, based on gcc version 3.1 20020420

g++ foo.cpp
ld: Undefined symbols: <-- ERROR
vtable for Foo

Any idea why?
-r
**************** contents of foo.cpp **********

class Foo {

protected:
void setit(int);

public:
virtual void bar(); // only a subclass implements
};
class Bird : public Foo {

public:
void bar();
};

// ################

int a;

void Foo::setit(int i) {
a = i;
}

void Bird::bar() {
Foo::setit(8);
}

int main(int argc, char **argv) {
Bird *b = new Bird();
b->bar();
}

// end
Jul 19 '05 #1
2 11163
r wrote:
I compile this on a Max OSX with
GCC version 1151, based on gcc version 3.1 20020420

g++ foo.cpp
ld: Undefined symbols: <-- ERROR
vtable for Foo

Any idea why?
-r
**************** contents of foo.cpp **********

class Foo {

protected:
void setit(int);

public:
virtual void bar(); // only a subclass implements
try:
virtual void bar() = 0;
virtual void bar() indicates that the compiler expects there to be an
implementation.

};
class Bird : public Foo {

public:
void bar();
};

// ################

int a;

void Foo::setit(int i) {
a = i;
}

void Bird::bar() {
Foo::setit(8);
}

int main(int argc, char **argv) {
Bird *b = new Bird();
b->bar();
}

// end


Jul 19 '05 #2
r wrote in news:38*************************@posting.google.co m:
I compile this on a Max OSX with

GCC version 1151, based on gcc version 3.1 20020420

g++ foo.cpp
ld: Undefined symbols: <-- ERROR
vtable for Foo

[snip]
class Foo {

protected:
void setit(int);

public:
change this:
virtual void bar(); // only a subclass implements
To:

virtual void bar() = 0;

};
class Bird : public Foo {

public:
void bar();
};

// ################
int a;

[snip]

Adding the = 0; to the declaration of bar() above makes bar()
a pure virtual and Foo an abstract class. In effect telling
the compiler you want to derive from Foo but NOT create any
instances of Foo. The compiler can then omit creating a vtable
for Foo and your linker error will go away.

Alternatively provide an defenition for Foo::bar()

voif Foo::bar()
{
}

Do it this way if you want to create instances of Foo.

HTH

Rob.
--
http://www.victim-prime.dsl.pipex.com/
Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Stu | last post by:
I am trying to build the xerces shared library with 2.3.0 version of their source code on an AIX 5.1 32 bit machine with the following version of the g++ compiler /usr/local/bin/g++ -v Reading...
0
by: pervinder | last post by:
Hi, I have an application which uses math/matrix solving lib like blas, lapack. When i build the binary using forte7 , it passes. But when i change the compiler to forte8, i get 2 undefined symbol...
2
by: Thierry Dussuet | last post by:
Hello all! I am writing a small Qt program (a KDE kicker) right now, which has a main class (called infokicker) and a second class (called Worker). infokicker has a line Worker the_thread; in...
2
by: Joe Lester | last post by:
I'm just moved my Postgres client project from Mac 10.2.8 to 10.3.5. It's an Objective-C program that links to libpq.a (the header file is libpq-fe.h). However, when I try to compile now I get the...
0
by: Alexander Cohen | last post by:
IM trying to build the ppostgres ODBC driver for MacOSX. I thought id try and build it as a bundle from XCode. All compiles no problem but then at the end of the compile i get an undefined symbols...
6
by: Vijay Bajwa | last post by:
Once again, the FORTE 7.0 compiler on Sun screwed me. The error msgs are incomprehensible. There is the familiar STL linkage problem, libraries compile fine tho. it's only when I compile the main...
13
by: 7stud | last post by:
test1.py: -------------------- import shelve s = shelve.open("/Users/me/2testing/dir1/aaa.txt") s = "red" s.close() --------output:------ $ python test1.py
0
by: smartie | last post by:
Hello everybody, i'm writing some simple C code (in Mac OS X 10.4) that uses an openssl library. The library is included with: #include <openssl/bn.h> and I have installed it correctly...
4
by: Tex08 | last post by:
I did it again... after trashing the old code and trying to start simple, I receive the following error at compile (with g++, required)" g++ main.cc Undefined first...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.