undefined reference to `vtable for MyViz'
In the librviz_tutorial, myviz.h
resides in librviz_tutorial/src
. I'd like to move it to librviz_tutorial/include/librviz_tutorial
. In CMakeLists.txt
, I changed include_directories(${catkin_INCLUDE_DIRS})
to include_directories(include ${catkin_INCLUDE_DIRS})
, and catkin_package()
to catkin_package(INCLUDE_DIRS include)
. I also changed #include "myviz.h"
to #include "librviz_tutorial/myviz.h"
in both myviz.cpp
and main.cpp
However, I get the following error when building:
CMakeFiles/myviz.dir/src/myviz.cpp.o: In function `MyViz::MyViz(QWidget*)':
myviz.cpp:(.text+0x5d): undefined reference to `vtable for MyViz'
myviz.cpp:(.text+0x72): undefined reference to `vtable for MyViz'
CMakeFiles/myviz.dir/src/myviz.cpp.o: In function `MyViz::~MyViz()':
myviz.cpp:(.text+0x98e): undefined reference to `vtable for MyViz'
myviz.cpp:(.text+0x9a0): undefined reference to `vtable for MyViz'
collect2: error: ld returned 1 exit status
make[2]: *** [/home/user/workspace/devel/.private/librviz_tutorial/lib/librviz_tutorial/myviz] Error 1
make[1]: *** [CMakeFiles/myviz.dir/all] Error 2
make: *** [all] Error 2
I assume this has something to do with inheritance and virtual member functions. Is there anything I can add to CMakeLists.txt
to fix this? Or myviz
? Thanks.
It seems like the Qt MOC step may not be executing correctly, but without seeing your full CMakeLists.txt it's impossible to tell.
As I said in the post, I've only changed two things in the tutorial's CMakeLists.txt:
I changed
include_directories(${catkin_INCLUDE_DIRS})
toinclude_directories(include ${catkin_INCLUDE_DIRS})
, andcatkin_package()
tocatkin_package(INCLUDE_DIRS include)
You probably need to update https://github.com/ros-visualization/... for the new path to myviz.h .
Whoops, wrong branch. I'm using kinetic-devel. myviz.h isn't listed in CMakeLists.txt anymore.
Looks like you're running into this: https://stackoverflow.com/questions/2...