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. error LNK2005:... already defined in xxy.lib(xxz.obj)
Forum Updated to NodeBB v4.3 + New Features

error LNK2005:... already defined in xxy.lib(xxz.obj)

Scheduled Pinned Locked Moved Unsolved C++ Gurus
8 Posts 3 Posters 2.4k 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.
  • A Offline
    A Offline
    Alcor
    wrote on last edited by Alcor
    #1

    Visual Studio (both 2017 and 2022) gives the following linker error. StackExchange link (https://stackoverflow.com/questions/15421254/already-defined-in-obj-no-double-inclusions) says:

    "This is not a compiler error: the error is coming from the linker. ......The linker finds out that you have the same symbol defined multiple times in different translation units, and complains about it (it is a violation of the One Definition Rule)."

    I have files qteditorfactory.cpp and qteditorfactory.h. (corresponding to qteditorfactory.obj). But where do I find the source code corresponding to Qt5Widgetsd.dll?
    Or is there a better and different way to approach this problem? I have no clue where to start and fix the error. If someone can guide me, it will be of great help.
    Thank you.

    "7>Qt5Widgetsd.lib(Qt5Widgetsd.dll) : error LNK2005: "public: __cdecl QSpacerItem::QSpacerItem(int,int,enum QSizePolicy::Policy,enum QSizePolicy::Policy)" (??0QSpacerItem@@QEAA@HHW4Policy@QSizePolicy@@0@Z) already defined in qtpropertybrowserd.lib(qteditorfactory.obj)

    7>Qt5Widgetsd.lib(Qt5Widgetsd.dll) : error LNK2005: "public: __cdecl QSizePolicy::QSizePolicy(enum QSizePolicy::Policy,enum QSizePolicy::Policy,enum QSizePolicy::ControlType)" (??0QSizePolicy@@QEAA@W4Policy@0@0W4ControlType@0@@Z) already defined in qtpropertybrowserd.lib(qteditorfactory.obj)"

    JonBJ 1 Reply Last reply
    0
    • A Alcor

      Visual Studio (both 2017 and 2022) gives the following linker error. StackExchange link (https://stackoverflow.com/questions/15421254/already-defined-in-obj-no-double-inclusions) says:

      "This is not a compiler error: the error is coming from the linker. ......The linker finds out that you have the same symbol defined multiple times in different translation units, and complains about it (it is a violation of the One Definition Rule)."

      I have files qteditorfactory.cpp and qteditorfactory.h. (corresponding to qteditorfactory.obj). But where do I find the source code corresponding to Qt5Widgetsd.dll?
      Or is there a better and different way to approach this problem? I have no clue where to start and fix the error. If someone can guide me, it will be of great help.
      Thank you.

      "7>Qt5Widgetsd.lib(Qt5Widgetsd.dll) : error LNK2005: "public: __cdecl QSpacerItem::QSpacerItem(int,int,enum QSizePolicy::Policy,enum QSizePolicy::Policy)" (??0QSpacerItem@@QEAA@HHW4Policy@QSizePolicy@@0@Z) already defined in qtpropertybrowserd.lib(qteditorfactory.obj)

      7>Qt5Widgetsd.lib(Qt5Widgetsd.dll) : error LNK2005: "public: __cdecl QSizePolicy::QSizePolicy(enum QSizePolicy::Policy,enum QSizePolicy::Policy,enum QSizePolicy::ControlType)" (??0QSizePolicy@@QEAA@W4Policy@0@0W4ControlType@0@@Z) already defined in qtpropertybrowserd.lib(qteditorfactory.obj)"

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @Alcor
      You should not need to look at Qt sources which went into building Qt5Widgetsd.dll since you can just use the documentation of QSpacerItem::QSpacerItem/QSizePolicy::QSizePolicy to confirm they are exactly as reported in the error message.

      Although you say

      I have files qteditorfactory.cpp and qteditorfactory.h. (corresponding to qteditorfactory.obj).

      I think you have omitted to say this is third-party and has been used to build a qtpropertybrowserd.lib which you are linking against, right? qteditorfactory.cpp '#includes the Qt headers for these.

      I note that source code is 8 years old. Make sure you compile it and your own source code with consistent versions of Qt and compiler flags? Test compiling and linking it against an absolutely minimal main program of your own which just calls something in that library.

      A 2 Replies Last reply
      0
      • JonBJ JonB

        @Alcor
        You should not need to look at Qt sources which went into building Qt5Widgetsd.dll since you can just use the documentation of QSpacerItem::QSpacerItem/QSizePolicy::QSizePolicy to confirm they are exactly as reported in the error message.

        Although you say

        I have files qteditorfactory.cpp and qteditorfactory.h. (corresponding to qteditorfactory.obj).

        I think you have omitted to say this is third-party and has been used to build a qtpropertybrowserd.lib which you are linking against, right? qteditorfactory.cpp '#includes the Qt headers for these.

        I note that source code is 8 years old. Make sure you compile it and your own source code with consistent versions of Qt and compiler flags? Test compiling and linking it against an absolutely minimal main program of your own which just calls something in that library.

        A Offline
        A Offline
        Alcor
        wrote on last edited by
        #3

        @JonB said in error LNK2005:... already defined in xxy.lib(xxz.obj):

        I think you have omitted to say this is third-party and has been used to build a qtpropertybrowserd.lib which you are linking against, right?

        Yes.

        @JonB said in error LNK2005:... already defined in xxy.lib(xxz.obj):

        Make sure you compile it and your own source code with consistent versions of Qt and compiler flags? Test compiling and linking it against an absolutely minimal main program of your own which just calls something in that library.

        Good idea. Let me try.

        A 1 Reply Last reply
        0
        • A Alcor

          @JonB said in error LNK2005:... already defined in xxy.lib(xxz.obj):

          I think you have omitted to say this is third-party and has been used to build a qtpropertybrowserd.lib which you are linking against, right?

          Yes.

          @JonB said in error LNK2005:... already defined in xxy.lib(xxz.obj):

          Make sure you compile it and your own source code with consistent versions of Qt and compiler flags? Test compiling and linking it against an absolutely minimal main program of your own which just calls something in that library.

          Good idea. Let me try.

          A Offline
          A Offline
          Alcor
          wrote on last edited by Alcor
          #4

          @Alcor

          Just in case, if, this info helps in any way. I am able to separately compile and build this QtPropertyBrowser suite (modified for Qt5) using Visual Studio 2017. The generated .exe files for 7 example cases run fine.

          https://github.com/abhijitkundu/QtPropertyBrowser

          1 Reply Last reply
          0
          • JonBJ JonB

            @Alcor
            You should not need to look at Qt sources which went into building Qt5Widgetsd.dll since you can just use the documentation of QSpacerItem::QSpacerItem/QSizePolicy::QSizePolicy to confirm they are exactly as reported in the error message.

            Although you say

            I have files qteditorfactory.cpp and qteditorfactory.h. (corresponding to qteditorfactory.obj).

            I think you have omitted to say this is third-party and has been used to build a qtpropertybrowserd.lib which you are linking against, right? qteditorfactory.cpp '#includes the Qt headers for these.

            I note that source code is 8 years old. Make sure you compile it and your own source code with consistent versions of Qt and compiler flags? Test compiling and linking it against an absolutely minimal main program of your own which just calls something in that library.

            A Offline
            A Offline
            Alcor
            wrote on last edited by Alcor
            #5

            @JonB said in error LNK2005:... already defined in xxy.lib(xxz.obj):

            You should not need to look at Qt sources which went into building Qt5Widgetsd.dll since you can just use the documentation of QSpacerItem::QSpacerItem/QSizePolicy::QSizePolicy to confirm they are exactly as reported in the error message.

            #Include statement is on line 57

            #include <QSpacerItem>

            On line 2183 and 2392 it's being used as follows:

            lt->addItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Ignored));

            https://github.com/abhijitkundu/QtPropertyBrowser/blob/master/src/qteditorfactory.cpp

            Which matches with the constructor as defined in Qt5 documentation

            QSpacerItem::QSpacerItem(int w, int h, QSizePolicy::Policy hPolicy = QSizePolicy::Minimum, QSizePolicy::Policy vPolicy = QSizePolicy::Minimum)

            https://doc.qt.io/qt-5/qspaceritem.html#QSpacerItem

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mustafiz
              wrote on last edited by
              #6

              Did you try including QSizePolicy in qteditorfactory.cpp?

              #include <QSizePolicy>
              
              A 1 Reply Last reply
              0
              • M mustafiz

                Did you try including QSizePolicy in qteditorfactory.cpp?

                #include <QSizePolicy>
                
                A Offline
                A Offline
                Alcor
                wrote on last edited by
                #7

                @mustafiz said in error LNK2005:... already defined in xxy.lib(xxz.obj):

                #include <QSizePolicy>

                Yes. The error message persists.

                A 1 Reply Last reply
                0
                • A Alcor

                  @mustafiz said in error LNK2005:... already defined in xxy.lib(xxz.obj):

                  #include <QSizePolicy>

                  Yes. The error message persists.

                  A Offline
                  A Offline
                  Alcor
                  wrote on last edited by
                  #8

                  @Alcor

                  I remove the following line

                  add_compile_definitions(QT_STATIC)

                  in the CMakelists.txt (in the library files folder, not the client folder), and the link error goes away.
                  Yet to figure out if my .exe works as expected.

                  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