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. LNK2005 & LNK1169 error when use QMap between 2 dlls
Forum Updated to NodeBB v4.3 + New Features

LNK2005 & LNK1169 error when use QMap between 2 dlls

Scheduled Pinned Locked Moved Solved General and Desktop
10 Posts 3 Posters 1.1k 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.
  • R Offline
    R Offline
    rhoekath
    wrote on last edited by
    #1

    Hi, i'have an issue since 2days about an LNK2005 & LNK1169 error on MSVC 2015 (Qt 5.12.6)

    My error is:

    Core.lib(Core.dll) : error LNK2005: "public: __cdecl QMap<int,double>::~QMap<int,double>(void)" (??1?$QMap@HN@@QEAA@XZ) already defined in xxx.obj
    

    I have the error when i'm trying to compile a library (named AAA)
    The library AAA use Core.dll and both use a 2nd lib named Common.dll. The type QMap<int,double> is used in each libraries.

    When i'm looking xxx.obj (located in AAA), the only one usage i have of QMap<int,double>, is when i'm use a function that return a QMap and located in Core.dll

    I have lot of function defined in Core and used in AAA but i never seen this error before.

    I have check multiple things: trying to change the QMap with QVector, same type of error.
    I don't have any "include cpp file"
    I don't have the error when i'm using Clang or GCC to compile the project.
    I don't have the error if i'm using a QMap<int,double>*, but i don't want to

    I think it's an error related to the qmap template but i'm not sure

    Do you have an idea? Thanks

    Ps: i'v change the name of third lib (AAA) cause this is a code i use for my work and cannot share lot of things about it

    1 Reply Last reply
    0
    • JoeCFDJ Offline
      JoeCFDJ Offline
      JoeCFD
      wrote on last edited by JoeCFD
      #2

      When i'm looking xxx.obj (located in AAA), the only one usage i have of QMap<int,double>, is when i'm use a function that return a QMap and located in Core.dll

      Check if it is used in a header .h file. If yes, try to add #include <QMap> in it.
      It is not good enough to include <QMap> in its .cpp file

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi and welcome to devnet,

        How is that map declared ?
        Can you share the header files ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • R Offline
          R Offline
          rhoekath
          wrote on last edited by
          #4

          Thx for your messages,

          The issue is:

          I have a class named Serie with a function named getOrientations that return a QMap<int, double>. Serie is located in Core.dll
          I use an Serie object and the function getOrientations in another class named SortSeries (located in AAA).

          I have change my fonction getOrientations for returning a QMap<int, double>* (a ptr) and that work, but i don't need a ptr

          QMap is included in Serie.h and SortSeries.h.

          AAA and Core has already lot of other usage of QMap<int, double> (in other functions and objects) but when i want to use it between 2 libraries, i have this issue.

          I'v tested to change the return type of getOrientations by "QVector<double>" but same issue.

          Do Qt register the QMap template and they can be different between libraries ?

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Can you show the header of that Series class ?

            Note that unless you are doing forwarding, you need to include the header matching the class of your objects.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • R Offline
              R Offline
              rhoekath
              wrote on last edited by
              #6

              Here the .h of Serie, located in Core.dll

              #ifndef SERIE_H
              #define SERIE_H
              
              #include <QObject>
              
              #include "core_global.h"
              
              #include <QVector>
              #include <QMap>
              
              class CORESHARED_EXPORT Serie : public QObject
              {
                  Q_OBJECT
              
              public:
                  Serie(QString id = "");
              
                  QMap<int, double> getOrientations(int id = 0) const;
              
              };
              
              #endif // SERIE_H
              

              Here the .h of SortSeries, located in AAA.dll

              #ifndef SORTSERIES_H
              #define SORTSERIES_H
              
              #include "aaa_global.h"
              
              #include "Project/Serie.h"
              
              #include <QObject>
              
              class AAASHARED_EXPORT SortSeries : public QObject
              {
                  Q_OBJECT
              
              public:
                  SortSeries();
                  void setSeries(const QVector<Serie *> &series);
                  void apply();
                  QVector<Serie *> getSeries();
              
              private:
                  QVector<Serie*> _series;
              
              };
              
              #endif // SORTSERIES_H
              

              The function that use getOrientations is apply()

              I have removed lot of things cause this is confidential (my work). The projet contains 8 internal libraries and AAA used 4 of them. The type QMap<int, double> is used in many classes in the project but all classes that use that type include QMap (in .h if used in .h and in .cpp if used is .cpp).

              That why i have that question about the template, do Qt register it in AAA and in Core and they don't match if we want to share a QMap between the 2 libraries?

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                There's nothing special with QMap, it's just a template as any other.

                I am currently wondering whether you are not hitting a bug in MSVC.

                Your implementation looks mostly sane, one thing you can improve is using const String & for your Serie constructor. And also it builds fine with both GCC and CLANG.

                One thing you can do is use MSVC2017 or even 2019 since starting with 2017 they are backward compatible.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0
                • R Offline
                  R Offline
                  rhoekath
                  wrote on last edited by
                  #8

                  I will check my code with MSVC2017 or 2019 if i also have the pb or not

                  1 Reply Last reply
                  0
                  • R Offline
                    R Offline
                    rhoekath
                    wrote on last edited by rhoekath
                    #9

                    Pb fixed by replacing each usage of QMap<int, double> in Core and AAA by an custom object i created in a third library that used by both.
                    To see the pb, i have checked my dll by using Dependency Walker and i have see many definition of QMap<int, double> in Core and in another library.
                    But I don't know if is a problem with the compiler or not.
                    I will check later with another version of MSVC, I have to recompile lot of things to verify that.

                    I have used these website too:

                    • https://forum.qt.io/topic/43408/error-lnk2005-when-deriving-from-qvariantmap
                    • http://web.archive.org/web/20090323151858/https://mareq.com/2008/10/exporting-non-template-class-inherited.html

                    Thx for your help @SGaist & @JoeCFD

                    JoeCFDJ 1 Reply Last reply
                    0
                    • R rhoekath

                      Pb fixed by replacing each usage of QMap<int, double> in Core and AAA by an custom object i created in a third library that used by both.
                      To see the pb, i have checked my dll by using Dependency Walker and i have see many definition of QMap<int, double> in Core and in another library.
                      But I don't know if is a problem with the compiler or not.
                      I will check later with another version of MSVC, I have to recompile lot of things to verify that.

                      I have used these website too:

                      • https://forum.qt.io/topic/43408/error-lnk2005-when-deriving-from-qvariantmap
                      • http://web.archive.org/web/20090323151858/https://mareq.com/2008/10/exporting-non-template-class-inherited.html

                      Thx for your help @SGaist & @JoeCFD

                      JoeCFDJ Offline
                      JoeCFDJ Offline
                      JoeCFD
                      wrote on last edited by JoeCFD
                      #10

                      @rhoekath

                      add Qt naming space to it to see if it helps.

                      #ifndef SERIE_H
                      #define SERIE_H
                      
                      #include <QObject>
                      
                      #include "core_global.h"
                      
                      #include <QVector>
                      #include <QMap>
                      
                      QT_BEGIN_NAMESPACE
                      
                      class CORESHARED_EXPORT Serie : public QObject
                      {
                          Q_OBJECT
                          .......
                      };
                      
                      QT_END_NAMESPACE
                      
                      #endif // SORTSERIES_H
                      
                      
                      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