<html><head><style>body{font-family:Helvetica,Arial;font-size:13px}</style></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;"><br></div> <div id="bloop_sign_1426008638090114048" class="bloop_sign"></div> <div>Hi,</div><div><br></div><div>I have just run into this problem a few weeks ago.  My explanation might not be perfect, but from what I understand, it is related to the fact that the libraries which Qt depends upon have to be available for static linking to your application.  Those dependencies are “magically” brought in by qmake, but the CMake find package for Qt does not bring those in.  There have been some attempts, from what I gather, but nothing official for static linking of Qt applications with CMake.  Thus, my approach has been to find the system libraries myself using CMake and add them to the target_link_libraries() command.  Not much fun or robust (from my perspective), but works.  I have been able to statically compile and run the application on a colleague’s computer (where Qt was not installed at all).</div><div><br></div><div>There is also the concern of the plugins, mainly the platform plugins concept of Qt, which have to be compiled into your application.  If I understand correctly, when you request static linking from qmake (+= static), qmake creates a cpp file and adds it to your project.  This file simply contains code to insure that the plugins are compiled and can be linked against.  For CMake, you have to manually add these includes.  I do it in the main.cpp file or whatever file your main is in.</div><div><br></div><div>Here are links to the earlier discussion:</div><div><a href="https://www.mail-archive.com/cmake%40cmake.org/msg51188.html">https://www.mail-archive.com/cmake%40cmake.org/msg51188.html</a></div><div><a href="https://www.mail-archive.com/cmake%40cmake.org/msg51170.html">https://www.mail-archive.com/cmake%40cmake.org/msg51170.html</a></div><div><br></div><div>Stephen Kelly is much more knowledgable then me on this.  He usually responds pretty fast to the list (he helped me a lot on that).</div><div>Hope my explanations are not too confusing and that they help a little.</div><div>Best of luck.</div><div><br></div><div>Ghyslain</div><div><br></div><br><blockquote type="cite" class="clean_bq"><span><div><div><br>This has been driving me crazy for a while now. Occurs for both OSX and
<br>Linux.
<br>
<br>OSX Mavericks 10.9.5, openSUSE Linux 12.3
<br>CMake 3.1.1
<br>Qt 5.4.1 (both shared and static builds, compiled from source)
<br>
<br>Using cmake to compile and link the simple Qt HelloWorld app against Qt
<br>shared libraries works just fine.
<br>
<br>Using the same cmake file and specifying the Qt static libraries instead,
<br>it fails in the linking (OSX: Undefined symbols for architecture x86_64,
<br>ld: symbol(s) not found for architecture x86_64?; LINUX: undefined
<br>reference to ?, collect2 error: ld returned 1 exit status)
<br>
<br>Message would seem to point towards static libraries not compiled 64 bit.
<br>
<br>But, if I use qmake to generate the makefile to use with the Qt static
<br>libraries, it compiles and links with no problem. No symbol problem here.
<br>Seems to indicate the static libraries are fine.
<br>
<br>Since using qmake seems to work fine I can?t pin down what the problem is
<br>with cmake.
<br>
<br>Can anyone shed some light on this?
<br>
<br>Source, CMakeLists.txt, and qmake .pro contents below. I?ve also attached
<br>failed linking output from OSX and linux cmake/make.
<br>
<br>main.cpp:
<br>
<br>#include <QApplication>
<br>#include <QPushButton>
<br>
<br>int main(int argc, char **argv)
<br>{
<br>    QApplication app (argc, argv);
<br>
<br>    QPushButton button ("Hello world !");
<br>    button.show();
<br>
<br>    return app.exec();
<br>}
<br>
<br>
<br>CMakeLists.txt:
<br>
<br>cmake_minimum_required(VERSION 2.8.11)
<br>
<br>project(helloworld)
<br>set(CMAKE_INCLUDE_CURRENT_DIR ON)
<br>set(CMAKE_AUTOMOC ON)
<br>find_package(Qt5Widgets REQUIRED)
<br>add_executable(helloworld main.cpp)
<br>target_link_libraries(helloworld Qt5::Widgets)
<br>
<br>
<br>main.pro:
<br>
<br>SOURCES = main.cpp
<br>CONFIG += qt warn_on release
<br>QT += core widgets gui
<br>
<br>
<br>Thanks in advance.
<br><br></div></div></span></blockquote></body></html>