⚠️ Forum Maintenance: Feb 6th, 8am - 14pm (UTC+2)

Undefined reference to qInitResources

  • 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:


    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?

    My OS: Windows 10

  • @Montjet said in Undefined reference to qInitResources:


    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.

  • It doesn't work :(

  • 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 :{

  • @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. :)

Log in to reply