Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Linking static vs shared libraries (Qt 6 CMake)

Linking static vs shared libraries (Qt 6 CMake)

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 1.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    paulmasri
    wrote on last edited by
    #1

    Could someone explain the following please.

    If I create a SHARED library as follows...

    qt_add_library(NovaLib SHARED)
    
    qt_add_qml_module(NovaLib
      URI Nova
      ...)
    
    qt_add_executable(app
      main.cpp)
    
    qt_add_qml(app
      URI MyApp VERSION 1.0
      QML_FILES main.qml)
    

    then I need to link to the library itself

    target_link_libraries(app PRIVATE ... NovaLib)
    

    But if I create a STATIC library as follows...

    qt_add_library(NovaLib STATIC)
    
    qt_add_qml_module(NovaLib
      URI Nova
      ...)
    
    qt_add_executable(app
      main.cpp)
    
    qt_add_qml(app
      URI MyApp VERSION 1.0
      QML_FILES main.qml)
    

    then I need to link to the library plugin

    target_link_libraries(app PRIVATE ... NovaLibplugin)
    

    Why is this?

    NB: when I say "I need to", I mean that if I don't do it this way then either I get a CMake error (linking SHARED library plugin) or it builds but I get a QML runtime error using import Nova (linking STATIC library itself).

    1 Reply Last reply
    0
    • JoeCFDJ Offline
      JoeCFDJ Offline
      JoeCFD
      wrote on last edited by
      #2

      target_link_libraries( ${PROJECT_NAME} path/NovaLib.a ) should work.

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved