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

Hendrik Sattler post at hendrik-sattler.de
Tue Mar 10 13:40:59 EDT 2015


Hi,

that's because qmake uses its some extra files to track the additional libraries that are needed when you link qt statically (.prl IIRC).
You are missing these, somehow. Maybe the cmake files from qt5 don't handle this case?

HS


Am 10. März 2015 18:28:18 MEZ, schrieb paul johnson <p77johnson at gmail.com>:
>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
>
>
>------------------------------------------------------------------------
>
>-- 
>
>Powered by www.kitware.com
>
>Please keep messages on-topic and check the CMake FAQ at:
>http://www.cmake.org/Wiki/CMake_FAQ
>
>Kitware offers various services to support the CMake community. For
>more information on each offering, please visit:
>
>CMake Support: http://cmake.org/cmake/help/support.html
>CMake Consulting: http://cmake.org/cmake/help/consulting.html
>CMake Training Courses: http://cmake.org/cmake/help/training.html
>
>Visit other Kitware open-source projects at
>http://www.kitware.com/opensource/opensource.html
>
>Follow this link to subscribe/unsubscribe:
>http://public.kitware.com/mailman/listinfo/cmake
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20150310/6df0bc8e/attachment.html>


More information about the CMake mailing list