[CMake] Mixed linking

Ghyslain Leclerc ghleclerc at gmail.com
Fri Feb 6 10:04:33 EST 2015


Hello again.  Thanks for the answers.

To Stephen Kelly:

>> Here are a few questions for the list (hoping someone more knowledgable
>> than me will read this and help):
>>
>> 1) Am I right when I say CMake, Qt and static linking don?t mix ?

>They should mix fine.

Alright, I won't give up just yet.  :-)

>> I have tried on OS X. I have compiled a static version of Qt, making
>> sure I explicitly enable every plugin I need. Then, I have used the
>> following CMake code :

>I recommend starting with a minimal testcase, make sure it runs, and add
>things until it doesn't. Find the change that breaks.

Thanks for the suggestion.  Just did.  Here is the code for CMake:

# Some definitions to setup Qt
set( CMAKE_INCLUDE_CURRENT_DIR ON )
set( CMAKE_AUTOMOC ON )
set( QT_STATIC TRUE )
add_definitions( -DQT_STATIC )
if( "${CMAKE_BUILD_TYPE}" MATCHES Release )
   add_definitions(-DQT_NO_DEBUG_OUTPUT)
endif()


# Find Qt packages
find_package( Qt5Widgets )

# Find Qt dependencies
find_library( COREFOUNDATION_LIBRARY CoreFoundation )
find_library( COCOA_LIBRARY Cocoa )
find_library( CARBON_LIBRARY Carbon )
find_library( OPENGL_LIBRARY OpenGL )


include_directories( ${CMAKE_CURRENT_LIST_DIR} )
add_executable( helwrld main.cpp )
target_link_libraries( helwrld  Qt5::Widgets ${COREFOUNDATION_LIBRARY}
                                             ${COCOA_LIBRARY}
                                             ${CARBON_LIBRARY}
                                             ${OPENGL_LIBRARY}

"/sw/local/qt/lib/libqtharfbuzzng.a"
                                             z )



And here is the main.cpp file


#include <QApplication>
#include <QLabel>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    QLabel *label = new QLabel("Hello Qt!");
    label->show();
    return a.exec();
}

Don't know how to make it simpler.  Using the code compiles and links,
but still won't run.  Maybe my Qt static compilation was missing
something.  I will try and look into that.


To Norbert Pfeiler :

> Currently you have to define ?QT_STATIC? and explicitly include your
> required plugins in the code to get it working.

Thanks for the tips.  I looked up and now define QT_STATIC.  But I
just don't know how to include the plugins.  Actually, I always get
the error about the platform plugin (cocoa in my case).  Any tips ?

Thank you to all !
Ghyslain


More information about the CMake mailing list