[vtk-developers] linking vtk and qt
Waldin Nicholas
nwaldin at student.ethz.ch
Fri Jul 26 05:22:21 EDT 2013
Hi,
I'm trying to combine qt and vtk, and I'm getting "undefined reference errors". ccmake links everything, then when I type make I get the errors. Any help would be appreciated.
my cmakelists:
cmake_minimum_required(VERSION 2.8.5 FATAL_ERROR)
PROJECT (myqtvtk)
if(NOT VTK_BINARY_DIR)
find_package(VTK COMPONENTS
pqWidgets
pqCore
pqComponents
pqApplicationComponents
)
include(${VTK_USE_FILE})
endif()
find_package(Qt4 REQUIRED)
include(${QT_USE_FILE})
include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
file(GLOB UI_FILES *.ui)
file(GLOB QT_WRAP *.h)
file(GLOB CXX_FILES *.cxx)
QT4_WRAP_UI (UISrcs ${UI_FILES})
QT4_WRAP_CPP (MOCSrcs ${QT_WRAP})
add_executable(myqtvtk MACOSX_BUNDLE ${CXX_FILES} ${UISrcs} ${MOCSrcs})
if (VTK_LIBRARIES)
if(${VTK_VERSION} VERSION_LESS "6")
target_link_libraries(myqtvtk ${VTK_LIBRARIES} QVTK)
else()
target_link_libraries(myqtvtk ${VTK_LIBRARIES})
endif()
else()
target_link_libraries(myqtvtk vtkHybrid QVTK vtkViews ${QT_LIBRARIES})
endif()
the errors:
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
CMakeFiles/myqtvtk.dir/moc_mainwindow.cxx.o: In function `MainWindow::qt_static_metacall(QObject*, QMetaObject::Call, int, void**)':
moc_mainwindow.cxx:(.text+0x3f): undefined reference to `MainWindow::setValues()'
moc_mainwindow.cxx:(.text+0x4d): undefined reference to `MainWindow::applyOpacity()'
CMakeFiles/myqtvtk.dir/moc_drawarea.cxx.o:(.rodata._ZTV8DrawArea[vtable for DrawArea]+0xa0): undefined reference to `DrawArea::mousePressEvent(QMouseEvent*)'
CMakeFiles/myqtvtk.dir/moc_drawarea.cxx.o:(.rodata._ZTV8DrawArea[vtable for DrawArea]+0xa8): undefined reference to `DrawArea::mouseReleaseEvent(QMouseEvent*)'
CMakeFiles/myqtvtk.dir/moc_drawarea.cxx.o:(.rodata._ZTV8DrawArea[vtable for DrawArea]+0xb8): undefined reference to `DrawArea::mouseMoveEvent(QMouseEvent*)'
CMakeFiles/myqtvtk.dir/moc_drawarea.cxx.o:(.rodata._ZTV8DrawArea[vtable for DrawArea]+0xf8): undefined reference to `DrawArea::paintEvent(QPaintEvent*)'
CMakeFiles/myqtvtk.dir/moc_drawarea.cxx.o:(.rodata._ZTV8DrawArea[vtable for DrawArea]+0x108): undefined reference to `DrawArea::resizeEvent(QResizeEvent*)'
collect2: ld returned 1 exit status
make[2]: *** [myqtvtk] Error 1
make[1]: *** [CMakeFiles/myqtvtk.dir/all] Error 2
make: *** [all] Error 2
Attaching all the source code is a bit long, so I'm going to cut out parts that aren't relevant
drawarea.h
class DrawArea : public QWidget
{
Q_OBJECT
*snip*
protected:
void mousePressEvent(QMouseEvent *event);
void mouseMoveEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *event);
void paintEvent(QPaintEvent *event);
void resizeEvent(QResizeEvent *event);
*snip*
}
drawarea.cpp
void DrawArea::mousePressEvent(QMouseEvent *event) {
*snip*
}
void DrawArea::mouseMoveEvent(QMouseEvent *event) {
*snip*
}
void DrawArea::mouseReleaseEvent(QMouseEvent *event) {
*snip*
}
void DrawArea::paintEvent(QPaintEvent *event) {
*snip*
}
void DrawArea::resizeEvent(QResizeEvent *event) {
*snip*
}
More information about the vtk-developers
mailing list