<br><br><div class="gmail_quote">On Thu, Jan 22, 2009 at 12:57 AM, Kermit Mei <span dir="ltr">&lt;<a href="mailto:kermit.mei@gmail.com">kermit.mei@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hello, I want to use the following files under the directory gui to<br>
creat a share library named FreeReciteGui.so .<br>
<br>
<br>
$ tree<br>
gui<br>
|-- CMakeLists.txt<br>
|-- MainWindow.cpp<br>
|-- MainWindow.h<br>
|-- MainWindow.ui<br>
|-- ReciterWidget.cpp<br>
|-- ReciterWidget.h<br>
|-- ScannerWidget.cpp<br>
|-- ScannerWidget.h<br>
|-- ScannerWidget.ui<br>
|-- TaskModel.cpp<br>
|-- TaskModel.h<br>
|-- TesterWidget.cpp<br>
`-- TesterWidget.h<br>
<br>
When I link the program to this library, it always hint me:<br>
<br>
Linking CXX shared library libFreeReciteGui.so<br>
[ 36%] Built target FreeReciteGui<br>
[ 94%] Built target FreeReciteCore<br>
Linking CXX executable ../bin/FreeRecite-core<br>
gui/libFreeReciteGui.so: undefined reference to `vtable for ScannerWidget&#39;<br>
gui/libFreeReciteGui.so: undefined reference to `ScannerWidget::complished()&#39;<br>
gui/libFreeReciteGui.so: undefined reference to `ScannerWidget::qt_metacall(QMetaObject::Call, int, void**)&#39;<br>
gui/libFreeReciteGui.so: undefined reference to `typeinfo for ScannerWidget&#39;<br>
gui/libFreeReciteGui.so: undefined reference to `vtable for MainWindow&#39;<br>
gui/libFreeReciteGui.so: undefined reference to `ScannerWidget::staticMetaObject&#39;<br>
gui/libFreeReciteGui.so: undefined reference to `ScannerWidget::metaObject() const&#39;<br>
gui/libFreeReciteGui.so: undefined reference to `ScannerWidget::qt_metacast(char const*)&#39;<br>
collect2: ld returned 1 exit status<br>
make[2]: *** [bin/FreeRecite-core] Error 1<br>
make[1]: *** [src/CMakeFiles/FreeRecite-core.dir/all] Error 2<br>
make: *** [all] Error 2<br>
$<br>
<br>
But, in my model-testing with qmake, ScannerWidget and it&#39;s subclass are all<br>
work well. So I think there must be something wrong with CMakeLists.txt here.<br>
Help me point it out, please.<br>
The contents of CMaskLists.txt is :<br>
<br>
$ cat ../src/gui/CMakeLists.txt</blockquote><div><br>Read the docs on TARGET_LINK_LIBRARIES and LINK_DIRECTORIES, there is a big difference.<br><br>You&#39;re missing a call to TARGET_LINK_LIBRARIES(FreeReciteGui foo) (after you call ADD_LIBRARY), where foo is the target that includes the ScannerWidget symbols.<br>
<br>Also, the call to LINK_DIRECTORIES() for something within your source code is not needed.&nbsp; As long as you TARGET_LINK_LIBRARIES() to a CMake generated target CMake will automatically include the proper paths at link time as well as all of the dependents of the linked target (provided they are registered with TARGET_LINK_LIBRARIES).<br>
&nbsp;</div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br>
# Include the core library.<br>
INCLUDE_DIRECTORIES(${FREERECITE_SOURCE_DIR}/src/core)<br>
<br>
LINK_DIRECTORIES(${FREERECITE_BINARY_DIR}/src/core)<br>
<br>
# with SET() command you can change variables or define new ones<br>
# here we define SAMPLE_SRCS variable that contains a list of all .cpp files<br>
# note that we don&#39;t need \ at the end of line<br>
SET( FRGUI_SRCS<br>
&nbsp;MainWindow.cpp<br>
&nbsp;ScannerWidget.cpp<br>
&nbsp;ReciterWidget.cpp<br>
&nbsp;TesterWidget.cpp<br>
&nbsp;TaskModel.cpp<br>
&nbsp;)<br>
<br>
# another list, this time it includes all header files that should be treated with moc<br>
SET( FRGUI_MOC_HDRS<br>
&nbsp;MainWindow.h<br>
&nbsp;ScannerWidget.h<br>
&nbsp;ReciterWidget.h<br>
&nbsp;TesterWidget.h<br>
&nbsp;TaskModel.h<br>
)<br>
<br>
# some .ui files<br>
SET( FRGUI_UIS<br>
&nbsp;MainWindow.ui<br>
&nbsp;ScannerWidget.ui<br>
&nbsp;)<br>
<br>
# and finally an resource file<br>
#SET( FRGUI_RCS<br>
# &nbsp;./src/rc/sample.qrc<br>
# &nbsp;)<br>
<br>
# enable warnings<br>
ADD_DEFINITIONS( -Wall )<br>
<br>
# by default only QtCore and QtGui modules are enabled<br>
# other modules must be enabled like this:<br>
<br>
#SET( QT_USE_QT3SUPPORT TRUE ) &nbsp;<br>
#SET( QT_USE_QTXML TRUE )<br>
<br>
# this command finds Qt4 libraries and sets all required variables<br>
# note that it&#39;s Qt4, not QT4 or qt4<br>
FIND_PACKAGE( Qt4 REQUIRED )<br>
<br>
# add some useful macros and variables<br>
# (QT_USE_FILE is a variable defined by FIND_PACKAGE( Qt4 ) that contains a path to CMake script)<br>
INCLUDE( ${QT_USE_FILE} )<br>
<br>
# this command will generate rules that will run rcc on all files from FRGUI_RCS<br>
# in result FRGUI_RC_SRCS variable will contain paths to files produced by rcc<br>
#QT4_ADD_RESOURCES( FRGUI_RC_SRCS ${FRGUI_RCS} )<br>
<br>
# this will run uic on .ui files:<br>
QT4_WRAP_UI( FRGUI_UI_HDRS ${FRGUI_UIS} )<br>
<br>
# and finally this will run moc:<br>
QT4_WRAP_CPP( FRGUI_MOC_SRCS ${FRGUI_MOC_HDRS} )<br>
<br>
# we need this to be able to include headers produced by uic in our code<br>
# (CMAKE_BINARY_DIR holds a path to the build directory,<br>
# while INCLUDE_DIRECTORIES() works just like INCLUDEPATH from qmake)<br>
INCLUDE_DIRECTORIES( ${CMAKE_BINARY_DIR}/src/gui )<br>
<br>
ADD_LIBRARY(FreeReciteGui SHARED<br>
&nbsp;${FRGUI_SRCS}<br>
&nbsp;${FRGUI_MOC_SRC}<br>
&nbsp;${FRGUI_UI_HDRS}<br>
&nbsp;)<br>
<br>
INSTALL(TARGETS FreeReciteGui LIBRARY DESTINATION lib)<br>
<br>
<br>
__________________________________________________________________<br>
<br>
Thank you, very much.<br>
<br>
Kermit Mei<br>
<br>
<br>
<br>
_______________________________________________<br>
CMake mailing list<br>
<a href="mailto:CMake@cmake.org" target="_blank">CMake@cmake.org</a><br>
<a href="http://www.cmake.org/mailman/listinfo/cmake" target="_blank">http://www.cmake.org/mailman/listinfo/cmake</a><br>
</blockquote></div><br><br clear="all"><br>-- <br>Philip Lowman<br>