[CMake] can't link simple qt example

Glenn Hughes ghughes02138 at gmail.com
Mon Dec 7 16:42:53 EST 2009


Posting a solution to my previous problem

I wasn't linking in the generated resource file.
Here's a working very short CMake file for building the "states" Qt4.6
example:

---
#basic stuff
PROJECT(states) # the name of your project
CMAKE_MINIMUM_REQUIRED(VERSION 2.4.0)

#find qt, and include qt macros
FIND_PACKAGE(Qt4 REQUIRED) # find and setup Qt4 for this project
INCLUDE(${QT_USE_FILE})

#set up src and rsrc variables
SET( states_SRCS main.cpp )
SET( states_RESOURCES states.qrc )

#generate moc dependencies, generate "resources as compiled binary data"
files
QT4_AUTOMOC(${states_SRCS})
QT4_ADD_RESOURCES( states_RESOURCES_SOURCES ${states_RESOURCES} )

#the moc files will be generated into the binary directory.
#Add this to the include search path so #include "main.moc" will work
INCLUDE_DIRECTORIES( ${CMAKE_BINARY_DIR} )

#make an executable target, and associate its sources, and declare what
external libraries its depends on
ADD_EXECUTABLE( states MACOSX_BUNDLE ${states_SRCS}
${states_RESOURCES_SOURCES} )
TARGET_LINK_LIBRARIES(states ${QT_LIBRARIES})
 ---

One thing of note: In order for QT4_AUTOMOC to work, I had to move the
definition of the Pixmap class into a new header file named main.h. It seems
in general putting your Q_OBJECT class defs in a header is required when
building Qt projects under CMake... but there's probably some way around it.

Cheers
G

On Fri, Dec 4, 2009 at 8:59 PM, Glenn Hughes <ghughes02138 at gmail.com> wrote:

> Hello all, I'm just getting going with CMake and qt, and I'm having a bit
> of a problem.
> I've assembled pretty much the simplest CMakeLists.txt file I can imagine
> for a very simple example qt project. (I'm trying to build the qt 4.6
> "states" example using CMake.)
>
> When I build, I get the following link errors:
>
> /usr/bin/ld: warning suggest use of -bind_at_load, as lazy binding may
> result in errors or different symbols being used
> /usr/bin/ld: Undefined symbols:
> qInitResources_states()
> /Developer/Examples/Qt/animation/states/states.build/Debug/states.build/Objects-normal/i386/main.o
> reference to undefined qInitResources_states()
> symbol typeinfo for QFactoryInterfaceused from dynamic library
> /Developer/SDKs/MacOSX10.4u.sdk/Library/Frameworks/QtCore.framework/QtCore(single
> module) not from earlier dynamic library
> QtGui.framework/Versions/4/QtGui(single module)
> symbol typeinfo for QEventTransitionPrivateused from dynamic library
> /Developer/SDKs/MacOSX10.4u.sdk/Library/Frameworks/QtCore.framework/QtCore(single
> module) not from earlier dynamic library
> QtGui.framework/Versions/4/QtGui(single module)
> symbol typeinfo for QAbstractItemModelPrivateused from dynamic library
> /Developer/SDKs/MacOSX10.4u.sdk/Library/Frameworks/QtCore.framework/QtCore(single
> module) not from earlier dynamic library
> QtGui.framework/Versions/4/QtGui(single module)
> symbol typeinfo for QAbstractEventDispatcherPrivateused from dynamic
> library
> /Developer/SDKs/MacOSX10.4u.sdk/Library/Frameworks/QtCore.framework/QtCore(single
> module) not from earlier dynamic library
> QtGui.framework/Versions/4/QtGui(single module)
> symbol typeinfo name for QFactoryInterfaceused from dynamic library
> /Developer/SDKs/MacOSX10.4u.sdk/Library/Frameworks/QtCore.framework/QtCore(single
> module) not from earlier dynamic library
> QtGui.framework/Versions/4/QtGui(single module)
> symbol typeinfo name for QEventTransitionPrivateused from dynamic library
> /Developer/SDKs/MacOSX10.4u.sdk/Library/Frameworks/QtCore.framework/QtCore(single
> module) not from earlier dynamic library
> QtGui.framework/Versions/4/QtGui(single module)
> symbol typeinfo name for QAbstractItemModelPrivateused from dynamic library
> /Developer/SDKs/MacOSX10.4u.sdk/Library/Frameworks/QtCore.framework/QtCore(single
> module) not from earlier dynamic library
> QtGui.framework/Versions/4/QtGui(single module)
> symbol typeinfo name for QAbstractEventDispatcherPrivateused from dynamic
> library
> /Developer/SDKs/MacOSX10.4u.sdk/Library/Frameworks/QtCore.framework/QtCore(single
> module) not from earlier dynamic library
> QtGui.framework/Versions/4/QtGui(single module)
> symbol vtable for QFactoryInterfaceused from dynamic library
> /Developer/SDKs/MacOSX10.4u.sdk/Library/Frameworks/QtCore.framework/QtCore(single
> module) not from earlier dynamic library
> QtGui.framework/Versions/4/QtGui(single module)
> symbol vtable for QEventTransitionPrivateused from dynamic library
> /Developer/SDKs/MacOSX10.4u.sdk/Library/Frameworks/QtCore.framework/QtCore(single
> module) not from earlier dynamic library
> QtGui.framework/Versions/4/QtGui(single module)
> symbol vtable for QAbstractItemModelPrivateused from dynamic library
> /Developer/SDKs/MacOSX10.4u.sdk/Library/Frameworks/QtCore.framework/QtCore(single
> module) not from earlier dynamic library
> QtGui.framework/Versions/4/QtGui(single module)
> symbol vtable for QAbstractEventDispatcherPrivateused from dynamic library
> /Developer/SDKs/MacOSX10.4u.sdk/Library/Frameworks/QtCore.framework/QtCore(single
> module) not from earlier dynamic library
> QtGui.framework/Versions/4/QtGui(single module)
> collect2: ld returned 1 exit status
>
> Here's my CMakeLists.txt file, which I've cobbled together from various
> online examples:
>
> project(states)
> cmake_minimum_required(VERSION 2.4.0)
> find_package(Qt4 REQUIRED)
>
> FIND_PACKAGE( Qt4 COMPONENTS QtCore QtGui ) # don't know if this was
> necessary... I'm grasping at straws trying to force link ordering
>
> include(${QT_USE_FILE})
>
> set(states_SRCS
>     main.cpp
> )
>
> qt4_automoc(${states_SRCS})
>
> SET( states_RESOURCES_SOURCES
>        states.qrc
>   )
>
> QT4_ADD_RESOURCES( states_RESOURCES_SOURCES ${states_RESOURCES} )
>
> INCLUDE_DIRECTORIES( . )
>
> SET(QT_LIBS "${QT_LIBRARIES}")
>
> ADD_EXECUTABLE( states MACOSX_BUNDLE ${states_SRCS} )
> target_link_libraries(states ${QT_LIBRARIES})
>
> #---
>
> Here's the command output:
> Ld
> /Developer/Examples/Qt/animation/states/Debug/states.app/Contents/MacOS/states
> normal i386
>     cd /Developer/Examples/Qt/animation/states
>     /usr/bin/g++-4.0 -o
> /Developer/Examples/Qt/animation/states/Debug/states.app/Contents/MacOS/states
> -L/Developer/Examples/Qt/animation/states/Debug
> -F/Developer/Examples/Qt/animation/states/Debug
> -F/Developer/SDKs/MacOSX10.4u.sdk/Library/Frameworks -filelist
> /Developer/Examples/Qt/animation/states/states.build/Debug/states.build/Objects-normal/i386/states.LinkFileList
> -arch i386 -Wl,-Y,1455 -mmacosx-version-min=10.4 -Wl,-search_paths_first
> -headerpad_max_install_names -framework QtGui -framework Carbon -framework
> AppKit -framework QtCore /usr/lib/libz.dylib -framework ApplicationServices
> -isysroot /Developer/SDKs/MacOSX10.4u.sdk
>
> As you can see both QtCore and QtGui are being passed to the link
> command... So, I'm at a bit of a loss. I've tried building both from the
> command line and in XCode with the same errors in both places. I've tried a
> bunch of different tweaks to the CMakeLists.txt file, throwing out the cache
> and everything else and re-make-making between tries, but the result is
> always the same.
>
> Any advice?
>
> TIA
> Glenn
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20091207/8a52bcac/attachment.htm>


More information about the CMake mailing list