[CMake] cmake + Qt4 compilation problem

Luis Roberto P. Paula luisrpp at gmail.com
Tue Sep 9 02:20:26 EDT 2008


Hello everyone!

I'm trying to compile a simple application using Qt4 with cmake, but I'm
stucked in this error:

[ 33%] Generating ui_mivgui.h
Scanning dependencies of target viewer
[ 66%] Building CXX object CMakeFiles/viewer.dir/main.o
[100%] Building CXX object CMakeFiles/viewer.dir/mivgui.o
Linking CXX executable viewer
CMakeFiles/viewer.dir/mivgui.o: In function `MivGui::MivGui(QWidget*)':
mivgui.cxx:(.text+0x14e): undefined reference to `vtable for MivGui'
mivgui.cxx:(.text+0x158): undefined reference to `vtable for MivGui'
CMakeFiles/viewer.dir/mivgui.o: In function `MivGui::MivGui(QWidget*)':
mivgui.cxx:(.text+0x2c6): undefined reference to `vtable for MivGui'
mivgui.cxx:(.text+0x2d0): undefined reference to `vtable for MivGui'
CMakeFiles/viewer.dir/mivgui.o: In function `MivGui::tr(char const*, char
const*)':
mivgui.cxx:(.text._ZN6MivGui2trEPKcS1_[MivGui::tr(char const*, char
const*)]+0x1e): undefined reference to `MivGui::staticMetaObject'
collect2: ld returned 1 exit status
make[2]: *** [viewer] Error 1
make[1]: *** [CMakeFiles/viewer.dir/all] Error 2
make: *** [all] Error 2

This is the code I have for mivgui.h:

#include "ui_mivgui.h"

class MivGui : public QMainWindow, private Ui::MivGui
{
   Q_OBJECT

   public:
      MivGui(QWidget *parent = 0);

   private slots:
    void open();
};

And for the mivgui.cxx:

#include <QtGui>
#include "mivgui.h"

MivGui::MivGui(QWidget *parent): QMainWindow(parent)
{
    setupUi(this);

    QDesktopWidget *desktop = QApplication::desktop();

    int screenWidth, width;
    int screenHeight, height;
    int x, y;
    QSize windowSize;

    screenWidth = desktop->width(); // get width of screen
    screenHeight = desktop->height(); // get height of screen

    windowSize = size(); // size of our application window
    width = windowSize.width();
    height = windowSize.height();

    // little computations
    x = (screenWidth - width) / 2;
    y = (screenHeight - height) / 2;
    y -= 50;

    // move window to desired coordinates
    move ( x, y );

    // make connections
    connect(actionOpen, SIGNAL(triggered()), this, SLOT(open()));
}

void MivGui::open()
{
    QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"),
QDir::currentPath());
}


CMakeLists.txt
----------------------------------------------------------------------------------------------------------------------------------------------

SET(SOURCES_CPP
 main.cxx
 mivgui.cxx)
MESSAGE( STATUS ${SOURCES_CPP} )

SET(SOURCES_H
 mivgui.h)
MESSAGE( STATUS ${SOURCES_H} )

SET(SOURCES_UI
 mivgui.ui)
MESSAGE( STATUS ${SOURCES_UI} )

FIND_PACKAGE(Qt4 REQUIRED)

include(${QT_USE_FILE})

QT4_WRAP_UI(SOURCES_UI_H ${SOURCES_UI})

#qt4_automoc(${SOURCES_H})

INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_BINARY_DIR} )

ADD_EXECUTABLE(viewer ${SOURCES_CPP} ${SOURCES_H} ${SOURCES_UI_H})

TARGET_LINK_LIBRARIES(viewer ${QT_LIBRARIES} ${QT_QTSQL_LIBRARIES})

----------------------------------------------------------------------------------------------------------------------------------------------

Does anybody know how to solve this problem?

PS: It works fine with qmake, but I need to use cmake in order to integrate
with some ITK functions.

Thanks,
Luis
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20080909/c6324d76/attachment.htm>


More information about the CMake mailing list