Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

multiple definition of qInitResources_



  • Hi,
    I've been trying to build and execute the completer Example from the Qt website and it shows me this error when I try to build it:

    error: multiple definition of `qInitResources_completer()'
    :-1: error: collect2: error: ld returned 1 exit status
    

    I'm on ubuntu 16.04 and I have copied these files from the published example with the exception of the completer.pro file :

    ~/completer.qrc
    ~/completer/fsmodel.cpp
    ~/completer/fsmodel.h
    ~/completer/main.cpp
    ~/completer/mainwindow.cpp
    ~/completer/mainwindow.h
    ~/completer/resources/wordlist.txt
    ~/completer/resources/countries.txt
    

    I also executed this command on a terminal to come up with the completer.cpp file:

    rcc -name "completer" -no-compress ~/completer/completer.qrc -o ~/completer/completer.cpp
    

    Here's the content of completer.pro

    QT       += core gui widgets
    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    TARGET = completer
    TEMPLATE = app
    DEFINES += QT_DEPRECATED_WARNINGS
    CONFIG += c++11
    SOURCES += \
            main.cpp \
            mainwindow.cpp \
        fsmodel.cpp \
        completer.cpp
    HEADERS += \
            mainwindow.h \
        fsmodel.h
    
    qnx: target.path = /tmp/$${TARGET}/bin
    else: unix:!android: target.path = /opt/$${TARGET}/bin
    #!isEmpty(target.path): INSTALLS += target
    
    #requires(qtConfig(completer))
    RESOURCES += ~/completer/completer.qrc
    target.path = $$[completer]/completer
    INSTALLS += target
    

    There are several other posts on the forum about the completer example but I've found no discussion on this problem.
    Thank you



  • @Thalessa said in multiple definition of qInitResources_:

    I have copied these files from the published example

    Can you try to run the example from the Qt dir (present in Examples\Qt-version\widgets\tools) and check if it gives same error?
    You can go to Qt Creators example section to launch the example


  • Lifetime Qt Champion

    @Thalessa said in multiple definition of qInitResources_:

    completer.cpp

    You must not add this generated file to your SOURCES since it's automatically added when adding the .qrc file to RESOURCES. Therefore the file is compiled (and linked) twice.



  • @Ratzz and @Christian-Ehrlicher thanks to both of you for replying.

    I've tried the example in qt dir and now it works.

    I also had to add these lines in CMakeLists.txt :

    qt5_add_resources(RSC completer.qrc)
    # if next line is not added -> error but it will still work
    set_property(SOURCE qrc_completer.cpp PROPERTY SKIP_AUTOMOC ON) 
    add_executable(completer ${SOURCE} ${RSC})
    

Log in to reply