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 11 Apr 2018, 08:54 last edited by MasterBlade 4 Nov 2018, 08:54
    #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
    • V Offline
      V Offline
      VRonin
      wrote on 11 Apr 2018, 08:54 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 12 Apr 2018, 01:40
      5
      • V VRonin
        11 Apr 2018, 08:54

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

        M Offline
        M Offline
        MasterBlade
        wrote on 12 Apr 2018, 01:40 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 1 Reply Last reply 12 Apr 2018, 04:51
        0
        • M MasterBlade
          12 Apr 2018, 01:40

          @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 Offline
          J Offline
          J.Hilk
          Moderators
          wrote on 12 Apr 2018, 04:51 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 12 Apr 2018, 06:34
          0
          • J J.Hilk
            12 Apr 2018, 04:51

            @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 12 Apr 2018, 06:34 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 A 2 Replies Last reply 12 Apr 2018, 06:39
            0
            • M MasterBlade
              12 Apr 2018, 06:34

              @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 Offline
              J Offline
              J.Hilk
              Moderators
              wrote on 12 Apr 2018, 06:39 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 12 Apr 2018, 07:19
              1
              • M MasterBlade
                12 Apr 2018, 06:34

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

                A Offline
                A Offline
                aha_1980
                Lifetime Qt Champion
                wrote on 12 Apr 2018, 06:57 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 J.Hilk
                  12 Apr 2018, 06:39

                  @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 12 Apr 2018, 07:19 last edited by MasterBlade 4 Dec 2018, 07:28
                  #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 12 Apr 2018, 07:48 last edited by mrjj 4 Dec 2018, 08:16
                    #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 12 Apr 2018, 09:32
                    2
                    • V Offline
                      V Offline
                      VRonin
                      wrote on 12 Apr 2018, 08:11 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 12 Apr 2018, 09:52
                      4
                      • mrjjM mrjj
                        12 Apr 2018, 07:48

                        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 12 Apr 2018, 09:32 last edited by MasterBlade 4 Dec 2018, 09:38
                        #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
                        • V VRonin
                          12 Apr 2018, 08:11

                          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 12 Apr 2018, 09:52 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?

                          V 1 Reply Last reply 12 Apr 2018, 09:54
                          0
                          • M MasterBlade
                            12 Apr 2018, 09:52

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

                            V Offline
                            V Offline
                            VRonin
                            wrote on 12 Apr 2018, 09:54 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 13 Apr 2018, 08:26
                            4
                            • V VRonin
                              12 Apr 2018, 09:54

                              @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 13 Apr 2018, 08:26 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

                              1/14

                              11 Apr 2018, 08:54

                              • Login

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