Gcc Error Undefined Reference To Vtable
Contents |
here for a quick overview of the site Help Center Detailed answers to any undefined reference to vtable for constructor questions you might have Meta Discuss the workings and policies
The Vtable Symbol May Be Undefined Because The Class Is Missing Its Key Function
of this site About Us Learn more about Stack Overflow the company Business Learn more undefined reference to vtable qt about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack
Undefined Reference To Vtable For Destructor
Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up GCC C++ Linker errors: Undefined reference to 'vtable for XXX', Undefined reference to 'ClassName::ClassName()' up vote 64 down vote favorite 27 I'm setting up a C++ project, on Ubuntu undefined reference to vtable for c++ x64, using Eclipse-CDT. I'm basically doing a hello world and linking to a commerical 3rd party library. I've included the header files, linked to their libraries, but I still get linker errors. Are there some possible problems here other than the obvious (e.g. I am 99% sure I'm linking to the correct library). Is there a way to confirm the static libraries I am linking to are 64bit? Is there a way to confirm that the library has the class (and methods) I am expecting it to have? Eclipse says: Building target: LinkProblem Invoking: GCC C++ Linker g++ -L/home/notroot/workspace/somelib-3/somelib/target/bin -o"LinkProblem" ./src/LinkProblem.o -lsomelib1 -lpthread -lsomelib2 -lsomelib3 ./src/LinkProblem.o: In function `main': /home/notroot/workspace/LinkProblem/Debug/../src/LinkProblem.cpp:17: undefined reference to `SomeClass::close()' ./src/LinkProblem.o: In function `SomeOtherClass': /home/notroot/workspace/somelib-3/somelib/include/sql/somefile.h:148: undefined reference to `SomeClass::SomeClass()' /home/notroot/workspace/somelib-3/somelib/include/sql/somefile.h:148: undefined reference to `vtable for SomeOtherClass' /home/notroot/workspace/somelib-3/somelib/include/sql/somefile.h:151: undefined reference to `SomeClass::~SomeClass()' ./src/LinkProblem.o: In function `~SomeOtherClass': /home/notroot/workspace/somelib-3/somelib/include/sql/somefile.h:140: undefined reference to `vtable for SomeOtherClass' /home/notroot/workspace/somelib-3/somelib/include/sql/somefile.h:140: undefined reference to `SomeClass::~SomeClass()' /home/notroot/workspace/somelib-3/somelib/include/sql/somefile.h:140: u
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies
Undefined Reference To `typeinfo For
of this site About Us Learn more about Stack Overflow the company
Undefined Reference To Vtable For Class C++
Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges undefined reference to `vtt Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: http://stackoverflow.com/questions/1095298/gcc-c-linker-errors-undefined-reference-to-vtable-for-xxx-undefined-refere Sign up Linker error: undefined reference to vtable [duplicate] up vote 2 down vote favorite This question already has an answer here: What is an undefined reference/unresolved external symbol error and how do I fix it? 25 answers I'm hoping that you can help me with my problem, this program is a theater reservation program. main.cpp { #include
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of http://stackoverflow.com/questions/9406580/c-undefined-reference-to-vtable-and-inheritance this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question http://www.cplusplus.com/forum/general/69623/ x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up undefined reference C++ Undefined Reference to vtable and inheritance up vote 19 down vote favorite 5 File A.h #ifndef A_H_ #define A_H_ class A { public: virtual ~A(); virtual void doWork(); }; #endif File Child.h #ifndef CHILD_H_ #define CHILD_H_ #include "A.h" class Child: public A { private: int x,y; public: Child(); ~Child(); void doWork(); }; #endif And Child.cpp #include "Child.h" Child::Child(){ x = 5; } undefined reference to Child::~Child(){...} void Child::doWork(){...}; The compiler says that there is a undefined reference to vtable for A. I have tried lots of different things and yet none have worked. My objective is for class A to be an Interface, and to seperate implementation code from headers. c++ inheritance vtable share|improve this question edited Feb 23 '12 at 23:49 Lightness Races in Orbit 217k36337583 asked Feb 23 '12 at 3:06 rjmarques 116119 4 You must define every non-pure virtual function that you declare. You don't need to define a non-virtual function that you declare but don't use. –Lightness Races in Orbit Feb 23 '12 at 23:51 add a comment| 3 Answers 3 active oldest votes up vote 46 down vote accepted Why the error & how to resolve it? You need to provide definitions for all virtual functions in class A. Only pure virtual functions are allowed to have no definitions. i.e: In class A both the methods: virtual ~A(); virtual void doWork(); should be defined(should have a body) e.g.: A.cpp void A::doWork() { } A::~A() { } Caveat: If you want your class A to act as a
on a plugin framework for an application, which will work by dynamically loading shared/dynamic libraries that contain classes (unknown to the application) that derive from base classes (known to the application). I'm using MinGW with GCC and GNU-Make. The compiler output is below, including the rather strange linker error. g++ -DBUILDING_DLL -c -o plugin.o classes.cpp g++ -shared -o plugin.dll plugin.o plugin.o:classes.cpp:(.text$_ZN9baseClassC2Ev[baseClass::baseClass()]+0x8): undefined reference to `vtable for baseClass' collect2: ld returned 1 exit status mingw32-make: *** [plugin.dll] Error 1 The problem appears to be in baseClass' constructor, which I haven't defined. I get the same error, but twice, if I define baseClass' constructor as 'baseClass() {}', as I did with derivedClass (see code). The code isn't too long, I'll post it below. Help is appreciated. I think I'm doing something wrong with constructors, but I'm not sure what. classes.h 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// classes.h #ifndef CLASSES_H #define CLASSES_H #ifdef BUILDING_DLL #define DLL_INTERFACE __declspec(dllexport) #else #define DLL_INTERFACE __declspec(dllimport) #endif class DLL_INTERFACE baseClass { public: virtual void testFunc(); }; class DLL_INTERFACE derivedClass : public baseClass { public: derivedClass() {}; ~derivedClass() {}; void testFunc(); private: void privateFunc(); }; #endif classes.cpp: 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// classes.cpp #include