[CMake] Errors when creating a share library for Qt-application ?

Kermit Mei kermit.mei at gmail.com
Thu Jan 22 00:57:01 EST 2009


Hello, I want to use the following files under the directory gui to
creat a share library named FreeReciteGui.so .


$ tree
gui
|-- CMakeLists.txt
|-- MainWindow.cpp
|-- MainWindow.h
|-- MainWindow.ui
|-- ReciterWidget.cpp
|-- ReciterWidget.h
|-- ScannerWidget.cpp
|-- ScannerWidget.h
|-- ScannerWidget.ui
|-- TaskModel.cpp
|-- TaskModel.h
|-- TesterWidget.cpp
`-- TesterWidget.h

When I link the program to this library, it always hint me:

Linking CXX shared library libFreeReciteGui.so
[ 36%] Built target FreeReciteGui
[ 94%] Built target FreeReciteCore
Linking CXX executable ../bin/FreeRecite-core
gui/libFreeReciteGui.so: undefined reference to `vtable for ScannerWidget'
gui/libFreeReciteGui.so: undefined reference to 
`ScannerWidget::complished()'
gui/libFreeReciteGui.so: undefined reference to 
`ScannerWidget::qt_metacall(QMetaObject::Call, int, void**)'
gui/libFreeReciteGui.so: undefined reference to `typeinfo for ScannerWidget'
gui/libFreeReciteGui.so: undefined reference to `vtable for MainWindow'
gui/libFreeReciteGui.so: undefined reference to 
`ScannerWidget::staticMetaObject'
gui/libFreeReciteGui.so: undefined reference to 
`ScannerWidget::metaObject() const'
gui/libFreeReciteGui.so: undefined reference to 
`ScannerWidget::qt_metacast(char const*)'
collect2: ld returned 1 exit status
make[2]: *** [bin/FreeRecite-core] Error 1
make[1]: *** [src/CMakeFiles/FreeRecite-core.dir/all] Error 2
make: *** [all] Error 2
$

But, in my model-testing with qmake, ScannerWidget and it's subclass are all
work well. So I think there must be something wrong with CMakeLists.txt 
here.
Help me point it out, please.
The contents of CMaskLists.txt is :

$ cat ../src/gui/CMakeLists.txt
# Include the core library.
INCLUDE_DIRECTORIES(${FREERECITE_SOURCE_DIR}/src/core)

LINK_DIRECTORIES(${FREERECITE_BINARY_DIR}/src/core)

# 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( FRGUI_SRCS
  MainWindow.cpp
  ScannerWidget.cpp
  ReciterWidget.cpp
  TesterWidget.cpp
  TaskModel.cpp
  )
 
# another list, this time it includes all header files that should be 
treated with moc
SET( FRGUI_MOC_HDRS
  MainWindow.h
  ScannerWidget.h
  ReciterWidget.h
  TesterWidget.h
  TaskModel.h
)

# some .ui files
SET( FRGUI_UIS
  MainWindow.ui
  ScannerWidget.ui
  )

# and finally an resource file
#SET( FRGUI_RCS
#  ./src/rc/sample.qrc
#  )

# 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 command will generate rules that will run rcc on all files from 
FRGUI_RCS
# in result FRGUI_RC_SRCS variable will contain paths to files produced 
by rcc
#QT4_ADD_RESOURCES( FRGUI_RC_SRCS ${FRGUI_RCS} )

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

# and finally this will run moc:
QT4_WRAP_CPP( FRGUI_MOC_SRCS ${FRGUI_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}/src/gui )

ADD_LIBRARY(FreeReciteGui SHARED
  ${FRGUI_SRCS}
  ${FRGUI_MOC_SRC}
  ${FRGUI_UI_HDRS}
  )

INSTALL(TARGETS FreeReciteGui LIBRARY DESTINATION lib)


__________________________________________________________________

Thank you, very much.

Kermit Mei





More information about the CMake mailing list