[CMake] Linking to Qt static libraries fails using cmake but not qmake (both OSX and Linux)

paul johnson p77johnson at gmail.com
Tue Mar 10 13:28:18 EDT 2015


This has been driving me crazy for a while now. Occurs for both OSX and
Linux.

OSX Mavericks 10.9.5, openSUSE Linux 12.3
CMake 3.1.1
Qt 5.4.1 (both shared and static builds, compiled from source)

Using cmake to compile and link the simple Qt HelloWorld app against Qt
shared libraries works just fine.

Using the same cmake file and specifying the Qt static libraries instead,
it fails in the linking (OSX: Undefined symbols for architecture x86_64,
ld: symbol(s) not found for architecture x86_64’; LINUX: undefined
reference to …, collect2 error: ld returned 1 exit status)

Message would seem to point towards static libraries not compiled 64 bit.

But, if I use qmake to generate the makefile to use with the Qt static
libraries, it compiles and links with no problem. No symbol problem here.
Seems to indicate the static libraries are fine.

Since using qmake seems to work fine I can’t pin down what the problem is
with cmake.

Can anyone shed some light on this?

Source, CMakeLists.txt, and qmake .pro contents below. I’ve also attached
failed linking output from OSX and linux cmake/make.

main.cpp:

#include <QApplication>
#include <QPushButton>

int main(int argc, char **argv)
{
    QApplication app (argc, argv);

    QPushButton button ("Hello world !");
    button.show();

    return app.exec();
}


CMakeLists.txt:

cmake_minimum_required(VERSION 2.8.11)

project(helloworld)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
find_package(Qt5Widgets REQUIRED)
add_executable(helloworld main.cpp)
target_link_libraries(helloworld Qt5::Widgets)


main.pro:

SOURCES = main.cpp
CONFIG += qt warn_on release
QT += core widgets gui


Thanks in advance.


Paul
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20150310/285cf3ac/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: make_static_osx.log
Type: application/octet-stream
Size: 71837 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/cmake/attachments/20150310/285cf3ac/attachment-0002.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: make_static_linux.log
Type: application/octet-stream
Size: 43720 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/cmake/attachments/20150310/285cf3ac/attachment-0003.obj>


More information about the CMake mailing list