[CMake] cmake + Qt4 compilation problem

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


Thanks for your help Christian, but I just solved the problem with the
following CMakeLists.txt file. In this solution I don't need to add
#include "mivgui.moc" at the end of file.


CMakeLists.txt
------------------------------------------------------------------------------------------------------------------------------------------------------------
# set project's name
PROJECT( sample )

# with SET() command you can change variables or define new ones
# here we define SAMPLE_SRCS variable that contains a list of all .cpp files
# note that we don't need \ at the end of line
SET( SAMPLE_SRCS
./mivgui.cxx
./main.cxx
)

# another list, this time it includes all header files that should be
treated with moc
SET( SAMPLE_MOC_HDRS
./mivgui.h
)

# some .ui files
SET( SAMPLE_UIS
./mivgui.ui
)

# enable warnings
ADD_DEFINITIONS( -Wall )

# by default only QtCore and QtGui modules are enabled
# other modules must be enabled like this:
SET( QT_USE_QT3SUPPORT TRUE )
SET( QT_USE_QTXML TRUE )

# this command finds Qt4 libraries and sets all required variables
# note that it's Qt4, not QT4 or qt4
FIND_PACKAGE( Qt4 REQUIRED )

# add some useful macros and variables
# (QT_USE_FILE is a variable defined by FIND_PACKAGE( Qt4 ) that contains a
path to CMake script)
INCLUDE( ${QT_USE_FILE} )

# this will run uic on .ui files:
QT4_WRAP_UI( SAMPLE_UI_HDRS ${SAMPLE_UIS} )

# and finally this will run moc:
QT4_WRAP_CPP( SAMPLE_MOC_SRCS ${SAMPLE_MOC_HDRS} )

# we need this to be able to include headers produced by uic in our code
# (CMAKE_BINARY_DIR holds a path to the build directory, while
INCLUDE_DIRECTORIES() works just like INCLUDEPATH from qmake)
INCLUDE_DIRECTORIES( ${CMAKE_BINARY_DIR} )

# here we instruct CMake to build "sample" executable from all of the source
files
ADD_EXECUTABLE( sample ${SAMPLE_SRCS} ${SAMPLE_MOC_SRCS} ${SAMPLE_UI_HDRS} )

# last thing we have to do is to tell CMake what libraries our executable
needs,
# luckily FIND_PACKAGE prepared QT_LIBRARIES variable for us:
TARGET_LINK_LIBRARIES( sample ${QT_LIBRARIES} )

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


On Tue, Sep 9, 2008 at 3:35 AM, Luis Roberto P. Paula <luisrpp at gmail.com>wrote:

> Oh... I left it commented just for testing. Wrong copy-paste... sorry.
>
> But even if this line is not commented, the same error message is
> displayed.
>
>
> On Tue, Sep 9, 2008 at 3:26 AM, Christian Ehrlicher <Ch.Ehrlicher at gmx.de>wrote:
>
>> > Von: "Luis Roberto P. Paula"
>> > 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
>> >
>> <snip>
>> >
>> > 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})
>> >
>> Why did you comment out this line?
>> You need to moc your header - otherwise you'll get linker errors like
>> above.
>>
>>
>> Christian
>> --
>> GMX startet ShortView.de. Hier findest Du Leute mit Deinen Interessen!
>> Jetzt dabei sein:
>> http://www.shortview.de/wasistshortview.php?mc=sv_ext_mf@gmx
>> _______________________________________________
>> CMake mailing list
>> CMake at cmake.org
>> http://www.cmake.org/mailman/listinfo/cmake
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20080909/7ab13df8/attachment.htm>


More information about the CMake mailing list