Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. Symbol(s) duplication

Symbol(s) duplication

Scheduled Pinned Locked Moved Solved C++ Gurus
2 Posts 1 Posters 908 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.
  • kshegunovK Offline
    kshegunovK Offline
    kshegunov
    Moderators
    wrote on last edited by
    #1

    Hi,
    I'm getting a "multiple definition" error from the linker for no obvious reason. I have a simple utility class and I've ruled out the usual suspects. Here's the (stripped down) code:

    qdaemonstate_p.h

    QT_DAEMON_BEGIN_NAMESPACE
    
    class QDaemonState
    {
    public:
        QDaemonState(const QString &);
    
        void setPath(const QString &);
        void setArguments(const QStringList &);
        // ...
        QString path() const;
        QStringList arguments() const;
    
    private:
        struct Data
        {
            Data(const QString &);
    
            // ...
        } d;
    };
    
    // ------------------------------------------------------------------------------------ //
    
    inline void QDaemonState::setArguments(const QStringList & arguments)
    {
        d.arguments = arguments;
    }
    
    inline QString QDaemonState::path() const
    {
        return d.path;
    }
    
    inline QStringList QDaemonState::arguments() const
    {
        return d.arguments;
    }
    
    // ...
    
    QT_DAEMON_END_NAMESPACE
    
    Q_DECLARE_METATYPE(QtDaemon::QDaemonFlags)
    

    qdaemonstate.cpp

    #include "qdaemonstate_p.h"
    
    // ...
    
    QT_DAEMON_BEGIN_NAMESPACE
    
    QDaemonState::Data::Data(const QString & daemonName)
        : name(daemonName), initdPrefix(defaultInitDPath), dbusPrefix(defaultDBusPath), dbusTimeout(defaultDBusTimeout)
    {
    }
    
    QDaemonState::QDaemonState(const QString & name)
        : d(name)
    {
    }
    
    void QDaemonState::setPath(const QString & path)
    {
        // ...
    }
    
    QT_DAEMON_END_NAMESPACE
    

    The exact errors I get are:

    /usr/bin/ld.gold: error: .obj/qdaemonstate.o: multiple definition of 'QtDaemon::QDaemonState::Data::Data(QString const&)'
    /usr/bin/ld.gold: .obj/qdaemonstate.o: previous definition here
    /usr/bin/ld.gold: error: .obj/qdaemonstate.o: multiple definition of 'QtDaemon::QDaemonState::Data::Data(QString const&)'
    /usr/bin/ld.gold: .obj/qdaemonstate.o: previous definition here
    /usr/bin/ld.gold: error: .obj/qdaemonstate.o: multiple definition of 'QtDaemon::QDaemonState::QDaemonState(QString const&)'
    /usr/bin/ld.gold: .obj/qdaemonstate.o: previous definition here
    /usr/bin/ld.gold: error: .obj/qdaemonstate.o: multiple definition of 'QtDaemon::QDaemonState::QDaemonState(QString const&)'
    /usr/bin/ld.gold: .obj/qdaemonstate.o: previous definition here
    /usr/bin/ld.gold: error: .obj/qdaemonstate.o: multiple definition of 'QtDaemon::QDaemonState::setPath(QString const&)'
    Makefile:120: recipe for target '../../lib/libQt5Daemon.so.0.1.0' failed
    // ...
    

    Obviously for some reason I get multiple instances for the out-of-line methods, but why I don't know yet.
    Any suggestions?

    Read and abide by the Qt Code of Conduct

    1 Reply Last reply
    0
    • kshegunovK Offline
      kshegunovK Offline
      kshegunov
      Moderators
      wrote on last edited by
      #2

      It turned out very trivial. There was a source file path passed twice to qmake, which wasn't immediately obvious because of the subdirs template (the duplicate was in an included .pri file). This caused qmake to generate two targets for said file, and the linker is complaining because it tries to link twice the same translation unit.

      Read and abide by the Qt Code of Conduct

      1 Reply Last reply
      5

      • Login

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