user1415372
user1415372

Reputation: 33

Strange output when compiling c++ code. Any Ideas?

When i compile my code i get a set of errors that appear to related to the output files as in the .o file. I'm not sure why these sorts of errors would occur. Any Ideas?

/tmp/ccjPLJVV.o: In function `PubSub::~PubSub()':
Video_process.cpp:(.text._ZN6PubSubD2Ev[_ZN6PubSubD5Ev]+0x12): undefined reference to `vtable for PubSub'
/tmp/ccjPLJVV.o: In function `main':
Video_process.cpp:(.text.startup+0x34): undefined reference to `vtable for PubSub'
Video_process.cpp:(.text.startup+0xeb): undefined reference to `PubSub::run()'
/tmp/ccjPLJVV.o:(.rodata._ZTI13Video_process[typeinfo for Video_process]+0x10): undefined reference to `typeinfo for PubSub'
collect2: ld returned 1 exit status

This is essentially the output i'm getting when I attempt to compile.

Upvotes: 0

Views: 159

Answers (3)

Walter
Walter

Reputation: 45444

this is an error message from the linker, not the compiler. The linker cannot find some symbols which are declared, but not defined, in some files it tries to link together to make (most likely) an executable. The solution is to provide the definitions, i.e. the (compiled) code with those definitions. That code may already exist and you just have to "link against it" (tell the linker to search for symbols there) or may not, in which case you have to provide it...

for example, add the file defining the implementations of class PubSub to the linker/compiler command line should help ...

Upvotes: 0

ern0
ern0

Reputation: 3172

Maybe you've implemented the method, but you have not linked it. If you're using GCC, -o flag is your friend; all your class .o files must be specified when compiling the main.cpp.

Upvotes: 0

Luchian Grigore
Luchian Grigore

Reputation: 258618

It appears you have unimplemented virtual methods.

class PubSub
{
    //virtual destructors, although pure
    //MUST have an implementation
    virtual ~PubSub() = 0 { } 

    /*virtual?*/ void Run(); // <--- have you implemented this one?
}; 

Upvotes: 1

Related Questions