Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. CMake link error resource file
Forum Updated to NodeBB v4.3 + New Features

CMake link error resource file

Scheduled Pinned Locked Moved Unsolved Qt Creator and other tools
5 Posts 2 Posters 3.5k Views 2 Watching
  • 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.
  • J Offline
    J Offline
    JanW
    wrote on 15 Feb 2017, 22:05 last edited by
    #1

    Hi,

    I'm setting up my environment for a C++/Qt Quick application (Windows VS2013 x64) with cmake. I'm having trouble to get a (shared) library be compiled and linked to my executable and using a resource file from it (just a simple qml file to test the setup).

    I have set(CMAKE_AUTOMOC ON) and set(CMAKE_AUTORCC ON) in my root CMakeLists.txt
    The CMakeLists.txt of my shared library is as follows (BEQMLResource.qrc is in the same directory as CMakeLists.txt):

        cmake_minimum_required(VERSION 3.2)
         
        if(UNIX)
            SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=gnu++11")
        endif()
         
        SET(QT_ROOT_DIR "C:/Qt/5.7/msvc2013_64/")
         
        set(QT_QMAKE_EXECUTABLE ${QT_ROOT_DIR}/bin/qmake)
         
        find_package(Qt5 COMPONENTS Quick Core Network Widgets Gui Qml Positioning PATHS ${QT_ROOT_DIR})
         
        project("BEQML")
        set(PROJECT_RESOURCES BEQMLResource.qrc)
        qt5_add_resources(BEQML_RESOURCES ${PROJECT_RESOURCES})
        file(GLOB BEQML_SRC_LIBRARY
        	"BEQMLLibrary.h" #contains dll import/export defines for windows.
        	"BEQMLLibraryInitializer.cpp" #dummy class with some functions so the library is created.
        	"BEQMLLibraryInitializer.h"
        )
        source_group("Library"		FILES ${BEQML_SRC_LIBRARY})
        add_library(BEQML SHARED ${BEQML_SRC_LIBRARY} ${BEQML_RESOURCES})
        target_include_directories(BEQML PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../BELibraries/)
    

    When I compile the library, I get two linker errors in qrc_BEQMLResource.obje (unresolved external symbol for qRegisterResourceData and qUnregisterResourceData).
    Any idea what can be wrong?
    Kind regards,

    Jan

    A 1 Reply Last reply 16 Feb 2017, 00:03
    0
    • J JanW
      15 Feb 2017, 22:05

      Hi,

      I'm setting up my environment for a C++/Qt Quick application (Windows VS2013 x64) with cmake. I'm having trouble to get a (shared) library be compiled and linked to my executable and using a resource file from it (just a simple qml file to test the setup).

      I have set(CMAKE_AUTOMOC ON) and set(CMAKE_AUTORCC ON) in my root CMakeLists.txt
      The CMakeLists.txt of my shared library is as follows (BEQMLResource.qrc is in the same directory as CMakeLists.txt):

          cmake_minimum_required(VERSION 3.2)
           
          if(UNIX)
              SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=gnu++11")
          endif()
           
          SET(QT_ROOT_DIR "C:/Qt/5.7/msvc2013_64/")
           
          set(QT_QMAKE_EXECUTABLE ${QT_ROOT_DIR}/bin/qmake)
           
          find_package(Qt5 COMPONENTS Quick Core Network Widgets Gui Qml Positioning PATHS ${QT_ROOT_DIR})
           
          project("BEQML")
          set(PROJECT_RESOURCES BEQMLResource.qrc)
          qt5_add_resources(BEQML_RESOURCES ${PROJECT_RESOURCES})
          file(GLOB BEQML_SRC_LIBRARY
          	"BEQMLLibrary.h" #contains dll import/export defines for windows.
          	"BEQMLLibraryInitializer.cpp" #dummy class with some functions so the library is created.
          	"BEQMLLibraryInitializer.h"
          )
          source_group("Library"		FILES ${BEQML_SRC_LIBRARY})
          add_library(BEQML SHARED ${BEQML_SRC_LIBRARY} ${BEQML_RESOURCES})
          target_include_directories(BEQML PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../BELibraries/)
      

      When I compile the library, I get two linker errors in qrc_BEQMLResource.obje (unresolved external symbol for qRegisterResourceData and qUnregisterResourceData).
      Any idea what can be wrong?
      Kind regards,

      Jan

      A Offline
      A Offline
      ambershark
      wrote on 16 Feb 2017, 00:03 last edited by
      #2

      @JanW That indicates it isn't linking with Qt properly would be my guess.

      Try adding the line: qt5_use_modules(${PROJECT_NAME} Core) after your add_library line.

      My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

      1 Reply Last reply
      0
      • J Offline
        J Offline
        JanW
        wrote on 16 Feb 2017, 08:36 last edited by
        #3

        Thanks, that already solved my first problem! The BEQML library is building without errors, but now I got a link error in my executable project: unresolved external symbol qInitResource_BEQMLResource.
        The CMakeLists.txt from my exe project is as follows:

        cmake_minimum_required(VERSION 3.2 FATAL_ERROR)
        
        if(UNIX)
            SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=gnu++11")
        endif()
        
        set(CMAKE_INCLUDE_CURRENT_DIR ON)
        
        SET(QT_ROOT_DIR "C:/Qt/5.7/msvc2013_64/")
        
        set(QT_QMAKE_EXECUTABLE ${QT_ROOT_DIR}/bin/qmake)
        
        find_package(Qt5 COMPONENTS Quick Core Network Widgets Gui Qml Positioning PATHS ${QT_ROOT_DIR})
        
        project("StormExe")
        
        qt5_add_resources(RESOURCES StormExe.qrc)
        
        file(GLOB STORMEXE_SRC_QML
        	"QML/Main.qml"
        )
        file(GLOB STORMEXE_SRC_EXE
        	"Main.cpp"
        )
        
        source_group("Exe"	FILES ${STORMEXE_SRC_EXE})
        source_group("QML"	FILES ${STORMEXE_SRC_QML})
        
        add_executable(Storm ${STORMEXE_SRC_EXE} ${RESOURCES} ${STORMEXE_SRC_QML})
        qt5_use_modules(Storm Quick Core Network Widgets Gui Qml Positioning)
        
        target_link_libraries(Storm BEQML)
        target_include_directories(Storm PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../BELibraries/)
        

        In my Main.cpp i have:

        #include <QApplication>
        #include <QQmlApplicationEngine>
        
        int main(int argc, char *argv[])
        {
        	QApplication app(argc, argv);
        
        	Q_INIT_RESOURCE(BEQMLResource);
        
        	QQmlApplicationEngine engine;
        	engine.load(QUrl(QStringLiteral("qrc:/Main.qml")));
        
        	return app.exec();
        }
        

        Do I need to do something special to get access to the resources from the shared library?
        Regards,

        Jan

        Btw, if i build as a static lib, everything works just fine...

        1 Reply Last reply
        0
        • J Offline
          J Offline
          JanW
          wrote on 16 Feb 2017, 22:32 last edited by
          #4

          Ok, found a workaround by exporting a custom method from the dll which calls the initialisation of the resource like this:

          int BEQMLLibraryInitializer::init()
          {
          	extern int qInitResources_BEQMLResource();
          	return qInitResources_BEQMLResource();
          }
          

          Is there a better way to do it?
          Regards,

          Jan

          A 1 Reply Last reply 16 Feb 2017, 23:48
          0
          • J JanW
            16 Feb 2017, 22:32

            Ok, found a workaround by exporting a custom method from the dll which calls the initialisation of the resource like this:

            int BEQMLLibraryInitializer::init()
            {
            	extern int qInitResources_BEQMLResource();
            	return qInitResources_BEQMLResource();
            }
            

            Is there a better way to do it?
            Regards,

            Jan

            A Offline
            A Offline
            ambershark
            wrote on 16 Feb 2017, 23:48 last edited by
            #5

            @JanW This answers it better than I could:

            http://stackoverflow.com/questions/14633454/how-can-i-embed-a-qt-resource-into-a-dll-file

            Glad it's working for you now though. :)

            My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

            1 Reply Last reply
            0

            1/5

            15 Feb 2017, 22:05

            • Login

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