Qt4 and CMake (OT)

Alexander Neundorf neundorf at kde.org
Wed Jun 7 21:56:30 UTC 2006


Hi,

On Wednesday 31 May 2006 11:24, Patrick Noffke wrote:
> Apologies if this isn't the correct place for this question, but I
> recall hearing kdevelop is switching to cmake, so perhaps someone here
> can assist.
>
> I cannot for the life of me get moc to run when using cmake (2.4.2) on a
> Qt (4.1.3) project.  I have a library (xmlrpc) and this test harness
> (TestValues) that uses the QtTest library.  I've followed examples from
> this wiki:
>
> http://qtnode.net/wiki/Qt_with_cmake
>
> to get started on my CMakeLists.txt files.  I have another test harness
> that has no QObjects (and therefore nothing needs to be moc'ed), and
> that links and runs just fine.  But this test harness has a QObject
> subclass, and when I run make, I get the following output:
>
> Linking CXX executable values_test
> CMakeFiles/values_test.dir/TestValues.o(.gnu.linkonce.t._ZN10TestValuesD1Ev
>+0xb):
>
> In function `TestValues::~TestValues()':
> : undefined reference to `vtable for TestValues'
>
> CMakeFiles/values_test.dir/TestValues.o(.gnu.linkonce.t._ZN10TestValuesC1Ev
>+0x1b):
>
> In function `TestValues::TestValues()':
> : undefined reference to `vtable for TestValues'
>
> collect2: ld returned 1 exit status
> make[2]: *** [test/values/values_test] Error 1
> make[1]: *** [test/values/CMakeFiles/values_test.dir/all] Error 2
> make: *** [all] Error 2
>
> I've seen other indications that this error means moc hasn't run, and
> there are in fact no moc files around.  I've tried to #include
> "moc_TestValues.cpp" or #include "TestValues.moc" and that didn't help.
>
> Any tips on what I can try?  Are there other Qt4 + cmake examples out
> there?
>
>
>
> My CMakeLists.txt file for the test harness looks like this (it is a
> subdir of project(xmlrpc)):
>
> # the next line sets up include and link directories and defines some
> # variables that we will use.
> # you can modify the behavior by setting some variables, e.g.
> #   set(QT_USE_OPENGL TRUE)
> # -> this will cause cmake to include and link against the OpenGL module
> include(${QT_USE_FILE})
>
> include_directories (${xmlrpc_SOURCE_DIR}/src)
>
> link_directories (${xmlrpc_BINARY_DIR}/src)
>
> # the variable "values_test_SRCS" contains all .cpp files of this project
> set(values_test_SRCS
>     TestValues.cpp
> )
>
> set(values_test_MOC_SRCS
>     TestValues.h
> )
>
> # tell cmake to create .moc files for all files in the variable
> values_test_SRCS
> # that require such a file.
> # note: this assumes that you use #include "header.moc" in your files
> QT4_AUTOMOC(${values_test_SRCS})

What does your "#include "foo.moc" file look like exactly ?
For debugging you could insert some message(STATUS ...) in the FindQt4.cmake 
file to see what it does.

Bye
Alex
-- 
Work: alexander.neundorf AT jenoptik.com - http://www.jenoptik-los.de
Home: neundorf AT kde.org                - http://www.kde.org
      alex AT neundorf.net               - http://www.neundorf.net




More information about the KDevelop-devel mailing list