Qt4 and CMake (OT)
Patrick Noffke
pnoffke at bigpond.com
Wed May 31 09:24:30 UTC 2006
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})
#IF(QT4_WRAP_CPP)
#QT4_WRAP_CPP(values_test values_test.h)
#QT4_WRAP_CPP(values_test ${values_test_SRCS} ${values_test_MOC_SRCS})
#QT4_WRAP_CPP(values_test ${values_test_SRCS})
#ENDIF(QT4_WRAP_CPP)
# create an executable file named "values_test" from the source files in the
# variable "values_test_SRCS".
add_executable(values_test ${values_test_SRCS})
# link the "values_test" target against the Qt libraries. which libraries
# exactly, is defined by the "include(${QT_USE_FILE})" line above, which
sets
# up this variable.
target_link_libraries(values_test xmlrpc ${QT_QTTEST_LIBRARIES}
${QT_LIBRARIES})
More information about the KDevelop-devel
mailing list