Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Undefined reference to qInitResources
Forum Updated to NodeBB v4.3 + New Features

Undefined reference to qInitResources

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
5 Posts 2 Posters 11.7k Views 1 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.
  • M Offline
    M Offline
    Montjet
    wrote on last edited by Montjet
    #1

    Hi,
    I am trying to port my C++ application to Android.
    Unfortunately, I got error messages like:

    C:\myGame\src\shaders/carMaterial.cpp:28: error: undefined reference to 'CarMaterial::qInitResources_materials()'
    

    Android project files are made from CMakeList - without resources everything works fine.
    My CMakeList contains these lines:

    (...)
    QT5_ADD_RESOURCES("./resources/qml.qrc")
    
    SET(ALL_SOURCES
        ${__main_HDRSRC}
        (...)
        ${__resources_HDRSRC}   
    )
    
    IF(ANDROID)
        ADD_LIBRARY(myGame SHARED ${ALL_SOURCES})
    ELSE()
        ADD_EXECUTABLE(myGame WIN32 ${ALL_SOURCES})
    ENDIF()
    
    (...)
    

    I used toolchain from https://github.com/LaurentGomila/qt-android-cmake
    And command to making project files:

    cmake -DCMAKE_CXX_COMPILE_FEATURES=cxx_constexpr -DCMAKE_CXX_FLAGS="-std=gnu++14" -D ANDROID_NATIVE_API_LEVEL=android-19 -D CMAKE_TOOLCHAIN_FILE=../../qt-android-cmake/toolchain/android.toolchain.cmake -D CMAKE_MAKE_PROGRAM="%ANDROID_NDK%/prebuilt/windows-x86_64/bin/make.exe" -D QTDIR="%QTDIR%" -G "MinGW Makefiles" ..
    

    Any idea how to solve this problem?

    #edit
    My OS: Windows 10

    A 1 Reply Last reply
    0
    • M Montjet

      Hi,
      I am trying to port my C++ application to Android.
      Unfortunately, I got error messages like:

      C:\myGame\src\shaders/carMaterial.cpp:28: error: undefined reference to 'CarMaterial::qInitResources_materials()'
      

      Android project files are made from CMakeList - without resources everything works fine.
      My CMakeList contains these lines:

      (...)
      QT5_ADD_RESOURCES("./resources/qml.qrc")
      
      SET(ALL_SOURCES
          ${__main_HDRSRC}
          (...)
          ${__resources_HDRSRC}   
      )
      
      IF(ANDROID)
          ADD_LIBRARY(myGame SHARED ${ALL_SOURCES})
      ELSE()
          ADD_EXECUTABLE(myGame WIN32 ${ALL_SOURCES})
      ENDIF()
      
      (...)
      

      I used toolchain from https://github.com/LaurentGomila/qt-android-cmake
      And command to making project files:

      cmake -DCMAKE_CXX_COMPILE_FEATURES=cxx_constexpr -DCMAKE_CXX_FLAGS="-std=gnu++14" -D ANDROID_NATIVE_API_LEVEL=android-19 -D CMAKE_TOOLCHAIN_FILE=../../qt-android-cmake/toolchain/android.toolchain.cmake -D CMAKE_MAKE_PROGRAM="%ANDROID_NDK%/prebuilt/windows-x86_64/bin/make.exe" -D QTDIR="%QTDIR%" -G "MinGW Makefiles" ..
      

      Any idea how to solve this problem?

      #edit
      My OS: Windows 10

      A Offline
      A Offline
      ambershark
      wrote on last edited by
      #2

      @Montjet said in Undefined reference to qInitResources:

      QT5_ADD_RESOURCES("./resources/qml.qrc")

      This doesn't look right... You need something like:

      qt5_add_resources(RC_SRC "resources/qml.qrc")
      ...
      add_library(myGame SHARED ${ALL_SOURCES} ${RC_SRC})
      

      That should fix your issue. Basically that error message is saying you didn't include your resources in the shared object file so they can't be loaded.

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

      1 Reply Last reply
      4
      • M Offline
        M Offline
        Montjet
        wrote on last edited by
        #3

        It doesn't work :(

        1 Reply Last reply
        0
        • M Offline
          M Offline
          Montjet
          wrote on last edited by
          #4

          Okay, I got it!
          I moved every Q_INIT_RESOURCE(...) outside my namespace.
          Now, it's linked and works but my android app is crashed, I think it's a different issue :{

          A 1 Reply Last reply
          0
          • M Montjet

            Okay, I got it!
            I moved every Q_INIT_RESOURCE(...) outside my namespace.
            Now, it's linked and works but my android app is crashed, I think it's a different issue :{

            A Offline
            A Offline
            ambershark
            wrote on last edited by
            #5

            @Montjet Oh sorry I should have mentioned that. You can't have a namespace around Q_INIT_RESOURCES.

            It's covered in the Qt docs on using resources in a shared object. I didn't think to mention it.

            The crash is more than likely completely unrelated, so we'll consider this solved for now. Glad at least 1 part of your problem is over. :)

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

            1 Reply Last reply
            1

            • Login

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