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. multiple definition of qInitResources_
Forum Updated to NodeBB v4.3 + New Features

multiple definition of qInitResources_

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 2.0k 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.
  • T Offline
    T Offline
    Thalessa
    wrote on last edited by
    #1

    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

    RatzzR 1 Reply Last reply
    0
    • T Thalessa

      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

      RatzzR Offline
      RatzzR Offline
      Ratzz
      wrote on last edited by Ratzz
      #2

      @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

      --Alles ist gut.

      1 Reply Last reply
      2
      • Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @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.

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        1 Reply Last reply
        2
        • T Offline
          T Offline
          Thalessa
          wrote on last edited by Thalessa
          #4

          @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})
          
          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