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. Why do I have Multiple Definitions?
Forum Updated to NodeBB v4.3 + New Features

Why do I have Multiple Definitions?

Scheduled Pinned Locked Moved Solved General and Desktop
14 Posts 5 Posters 8.7k 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.
  • M Offline
    M Offline
    MasterBlade
    wrote on last edited by MasterBlade
    #1

    My code used to be all right, until I merged 2 header files.

    I have 'gameplay.cpp' and 'gameplay.h' file. But since there are so many contents in Gameplay, I added another header file (named 'card.h). This new header file contains many classes including functions.

    Today I just merged these 2 files but got a lot of 'multiple definition' error.
    It seems there's also a definition in moc_gameplay.o I don't even know what this file is.

    I'm sorry I can't paste my code here since it's too long. But I'll try to answer all your questions. There's nothing confidential about the game :)

    C:\Users\mfdsr\Documents\MasterZMDJ\gameplay.h:127: error: multiple definition of `MCard::CardInitialization()'

    C:\Users\mfdsr\Documents\MasterZMDJ\gameplay.h:127: first defined here

    C:\Users\mfdsr\Documents\build-MasterZMDJ-Desktop_Qt_5_10_1_MinGW_32bit-Debug\debug\moc_gameplay.o:-1: In function `ZN5MCardD1Ev':

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      https://en.wikipedia.org/wiki/Include_guard

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      M 1 Reply Last reply
      5
      • VRoninV VRonin

        https://en.wikipedia.org/wiki/Include_guard

        M Offline
        M Offline
        MasterBlade
        wrote on last edited by
        #3

        @VRonin said in Why do I have Multiple Definitions?:

        https://en.wikipedia.org/wiki/Include_guard

        Thanks for your reply. Actually I used a include guard like this.

        #ifndef GAMEPLAY_H
        #define GAMEPLAY_H

        I also tried to disable that include command and everything related to this file in the main window, still I have multiple definition problem.

        And through the error log, I found that the file is conflict with itself. All errors come from gameplay.h gameplay.o moc_gameplay.cpp gameplay.o

        J.HilkJ 1 Reply Last reply
        0
        • M MasterBlade

          @VRonin said in Why do I have Multiple Definitions?:

          https://en.wikipedia.org/wiki/Include_guard

          Thanks for your reply. Actually I used a include guard like this.

          #ifndef GAMEPLAY_H
          #define GAMEPLAY_H

          I also tried to disable that include command and everything related to this file in the main window, still I have multiple definition problem.

          And through the error log, I found that the file is conflict with itself. All errors come from gameplay.h gameplay.o moc_gameplay.cpp gameplay.o

          J.HilkJ Offline
          J.HilkJ Offline
          J.Hilk
          Moderators
          wrote on last edited by
          #4

          @MasterBlade
          do a complete clean, preferably delete your shadow build folder, rerun qmake and recompile.

          Let's see if that fixes it.


          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

          M 1 Reply Last reply
          0
          • J.HilkJ J.Hilk

            @MasterBlade
            do a complete clean, preferably delete your shadow build folder, rerun qmake and recompile.

            Let's see if that fixes it.

            M Offline
            M Offline
            MasterBlade
            wrote on last edited by
            #5

            @J.Hilk said in Why do I have Multiple Definitions?:

            @MasterBlade
            do a complete clean, preferably delete your shadow build folder, rerun qmake and recompile.

            Let's see if that fixes it.

            Sorry I'm new to qt. What is 'shadow build folder'? Does qmake mean 'Build All' in qt Creator?

            J.HilkJ aha_1980A 2 Replies Last reply
            0
            • M MasterBlade

              @J.Hilk said in Why do I have Multiple Definitions?:

              @MasterBlade
              do a complete clean, preferably delete your shadow build folder, rerun qmake and recompile.

              Let's see if that fixes it.

              Sorry I'm new to qt. What is 'shadow build folder'? Does qmake mean 'Build All' in qt Creator?

              J.HilkJ Offline
              J.HilkJ Offline
              J.Hilk
              Moderators
              wrote on last edited by
              #6

              @MasterBlade
              you'll finde the shadow build folder path in your project settings.
              Its a folder where all temporary files are created during the compile process and your executable will end up in

              0_1523515178384_f8f7964a-2097-4735-9e22-38ec9b1b4fdd-image.png


              Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


              Q: What's that?
              A: It's blue light.
              Q: What does it do?
              A: It turns blue.

              M 1 Reply Last reply
              1
              • M MasterBlade

                @J.Hilk said in Why do I have Multiple Definitions?:

                @MasterBlade
                do a complete clean, preferably delete your shadow build folder, rerun qmake and recompile.

                Let's see if that fixes it.

                Sorry I'm new to qt. What is 'shadow build folder'? Does qmake mean 'Build All' in qt Creator?

                aha_1980A Offline
                aha_1980A Offline
                aha_1980
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @MasterBlade

                Build > Run Qmake

                after that, do:

                Build > Rebuild

                Qt has to stay free or it will die.

                1 Reply Last reply
                0
                • J.HilkJ J.Hilk

                  @MasterBlade
                  you'll finde the shadow build folder path in your project settings.
                  Its a folder where all temporary files are created during the compile process and your executable will end up in

                  0_1523515178384_f8f7964a-2097-4735-9e22-38ec9b1b4fdd-image.png

                  M Offline
                  M Offline
                  MasterBlade
                  wrote on last edited by MasterBlade
                  #8

                  @J.Hilk @aha_1980
                  I tried to delete shadow folder ,run qmake, then rubuild all, still the same problem

                  I decided to upload the source file. It's fairly simple at this state. I know you experts do a much better job than me.

                  I can't upload file here. check this link for file 0_1523518096178_1.png

                  1 Reply Last reply
                  0
                  • mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by mrjj
                    #9

                    hi
                    the link opens an image of the link :)
                    Made me go ehh for for a moment.
                    https://files.fm/u/wh4n4f4a

                    update:
                    the rar file is empty for me.?

                    M 1 Reply Last reply
                    2
                    • VRoninV Offline
                      VRoninV Offline
                      VRonin
                      wrote on last edited by
                      #10

                      Do you have non-inline methods defined in the .h file? if so move them to the cpp file

                      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                      ~Napoleon Bonaparte

                      On a crusade to banish setIndexWidget() from the holy land of Qt

                      M 1 Reply Last reply
                      4
                      • mrjjM mrjj

                        hi
                        the link opens an image of the link :)
                        Made me go ehh for for a moment.
                        https://files.fm/u/wh4n4f4a

                        update:
                        the rar file is empty for me.?

                        M Offline
                        M Offline
                        MasterBlade
                        wrote on last edited by MasterBlade
                        #11

                        @mrjj said in Why do I have Multiple Definitions?:

                        hi
                        the link opens an image of the link :)
                        Made me go ehh for for a moment.

                        update:
                        the rar file is empty for me.?

                        Yeah, I also can't put links here. The page says it's an ad. ('Post content was flagged as spam by Akismet.com') Maybe you have a higher privilege than me :)

                        You can try this link. https://ufile.io/m53r2

                        The rar file looks alright to me. It's 205 KB.
                        0_1523525477714_2.PNG

                        1 Reply Last reply
                        0
                        • VRoninV VRonin

                          Do you have non-inline methods defined in the .h file? if so move them to the cpp file

                          M Offline
                          M Offline
                          MasterBlade
                          wrote on last edited by
                          #12

                          @VRonin said in Why do I have Multiple Definitions?:

                          Do you have non-inline methods defined in the .h file? if so move them to the cpp file

                          .h file has only classes. There are some functions in the classes of course. Some functions are lengthy and cannot be set as inline. Should I define them in the .cpp file?

                          VRoninV 1 Reply Last reply
                          0
                          • M MasterBlade

                            @VRonin said in Why do I have Multiple Definitions?:

                            Do you have non-inline methods defined in the .h file? if so move them to the cpp file

                            .h file has only classes. There are some functions in the classes of course. Some functions are lengthy and cannot be set as inline. Should I define them in the .cpp file?

                            VRoninV Offline
                            VRoninV Offline
                            VRonin
                            wrote on last edited by
                            #13

                            @MasterBlade said in Why do I have Multiple Definitions?:

                            Should I define them in the .cpp file?

                            Yes

                            "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                            ~Napoleon Bonaparte

                            On a crusade to banish setIndexWidget() from the holy land of Qt

                            M 1 Reply Last reply
                            4
                            • VRoninV VRonin

                              @MasterBlade said in Why do I have Multiple Definitions?:

                              Should I define them in the .cpp file?

                              Yes

                              M Offline
                              M Offline
                              MasterBlade
                              wrote on last edited by
                              #14

                              @VRonin said in Why do I have Multiple Definitions?:

                              @MasterBlade said in Why do I have Multiple Definitions?:

                              Should I define them in the .cpp file?

                              Yes

                              Wow that did solve my problem. Many Many Thanks!!!!!!

                              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