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. Error:undefined reference to..
Forum Updated to NodeBB v4.3 + New Features

Error:undefined reference to..

Scheduled Pinned Locked Moved Solved General and Desktop
15 Posts 5 Posters 15.0k 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.
  • S Offline
    S Offline
    seok
    wrote on 29 Nov 2021, 15:34 last edited by
    #1

    i am trying build the project i am getting "undefined reference " error
    but i have written the declaration and definition both

    i have tried changing the order of included header file
    i have tried cleaning the project and run qmake option as well
    in one of the post it was suggested to remove any function definition outside the class that also i did but no luck

    but the same source code is working fine in visual studio i don't understand why it is giving this error here

    please somebody help me resolve this (i cannot share the code here sorry for that)
    thank you in advance

    J J 2 Replies Last reply 29 Nov 2021, 15:39
    0
    • S seok
      29 Nov 2021, 15:34

      i am trying build the project i am getting "undefined reference " error
      but i have written the declaration and definition both

      i have tried changing the order of included header file
      i have tried cleaning the project and run qmake option as well
      in one of the post it was suggested to remove any function definition outside the class that also i did but no luck

      but the same source code is working fine in visual studio i don't understand why it is giving this error here

      please somebody help me resolve this (i cannot share the code here sorry for that)
      thank you in advance

      J Online
      J Online
      JonB
      wrote on 29 Nov 2021, 15:39 last edited by
      #2

      @seok said in Error:undefined reference to..:

      please somebody help me resolve this (i cannot share the code here sorry for that)

      You should show the code and the error. Asking people to help you with neither of these is not a good question.

      1 Reply Last reply
      1
      • S seok
        29 Nov 2021, 15:34

        i am trying build the project i am getting "undefined reference " error
        but i have written the declaration and definition both

        i have tried changing the order of included header file
        i have tried cleaning the project and run qmake option as well
        in one of the post it was suggested to remove any function definition outside the class that also i did but no luck

        but the same source code is working fine in visual studio i don't understand why it is giving this error here

        please somebody help me resolve this (i cannot share the code here sorry for that)
        thank you in advance

        J Offline
        J Offline
        jsulm
        Lifetime Qt Champion
        wrote on 29 Nov 2021, 15:41 last edited by
        #3

        @seok said in Error:undefined reference to..:

        "undefined reference "

        This error means that the source code file containing the undefined symbols is not linked (actually the object file created from that source code file).
        As @JonB suggested provide more information.

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        J S 2 Replies Last reply 29 Nov 2021, 15:49
        0
        • J jsulm
          29 Nov 2021, 15:41

          @seok said in Error:undefined reference to..:

          "undefined reference "

          This error means that the source code file containing the undefined symbols is not linked (actually the object file created from that source code file).
          As @JonB suggested provide more information.

          J Online
          J Online
          JonB
          wrote on 29 Nov 2021, 15:49 last edited by
          #4

          @jsulm
          I didn't even know for sure whether at least some compilers would give an Undefined reference to just for a missing symbol in a file at compile time, like int z = something_undefined? But it seems this does only come from the linker, the compiler must say something else for that, like Undeclared ... instead?

          J 1 Reply Last reply 30 Nov 2021, 05:35
          0
          • J jsulm
            29 Nov 2021, 15:41

            @seok said in Error:undefined reference to..:

            "undefined reference "

            This error means that the source code file containing the undefined symbols is not linked (actually the object file created from that source code file).
            As @JonB suggested provide more information.

            S Offline
            S Offline
            seok
            wrote on 29 Nov 2021, 15:50 last edited by
            #5

            @jsulm @JonB i am really sorry i know that it is wrong of me to not provide the code but i cannot really provide the code and as for the error

            "undefined reference to myfilter"
            where myfilter is a object of the class filter which is defined in filter.h file and the definition for the functions inside the class are written in filter.cpp file

            and in other file i am using myfilter object by using extern keyword

            J 1 Reply Last reply 29 Nov 2021, 15:53
            0
            • S seok
              29 Nov 2021, 15:50

              @jsulm @JonB i am really sorry i know that it is wrong of me to not provide the code but i cannot really provide the code and as for the error

              "undefined reference to myfilter"
              where myfilter is a object of the class filter which is defined in filter.h file and the definition for the functions inside the class are written in filter.cpp file

              and in other file i am using myfilter object by using extern keyword

              J Online
              J Online
              JonB
              wrote on 29 Nov 2021, 15:53 last edited by JonB
              #6

              @seok
              Could you clarify that you get this error message when the build process tries to link your object files together (after all files have been compiled), and not at compile-time, when the build is running the compiler on your source files?

              Assuming that is the case, the first possibility is the filter.o/.obj to be generated from the filter.cpp is not being linked with. Look carefully at your linker command line: do you see that object file at all there? This would sound like the only possibility if the sources really do work in Visual Studio.

              The next possibility is check 100 times that the spelling, including case, is identical where defined and where used in your source code.

              The next possibility is that you only have extern Filter *myfilter in your file(s). You must have some one place, in a .cpp file, which defines storage for the object, like Filter *myfilter, no extern.

              S 1 Reply Last reply 29 Nov 2021, 16:01
              0
              • J JonB
                29 Nov 2021, 15:53

                @seok
                Could you clarify that you get this error message when the build process tries to link your object files together (after all files have been compiled), and not at compile-time, when the build is running the compiler on your source files?

                Assuming that is the case, the first possibility is the filter.o/.obj to be generated from the filter.cpp is not being linked with. Look carefully at your linker command line: do you see that object file at all there? This would sound like the only possibility if the sources really do work in Visual Studio.

                The next possibility is check 100 times that the spelling, including case, is identical where defined and where used in your source code.

                The next possibility is that you only have extern Filter *myfilter in your file(s). You must have some one place, in a .cpp file, which defines storage for the object, like Filter *myfilter, no extern.

                S Offline
                S Offline
                seok
                wrote on 29 Nov 2021, 16:01 last edited by
                #7

                @JonB yes i am getting this error when the build process tries to link the object files together

                and how do i check the whether it is being linked or not (i don't know how to check the linker stage output in qt)

                (sorry for the late replay since i am a new user i can only post after 600 secs)

                J 1 Reply Last reply 29 Nov 2021, 16:01
                0
                • S seok
                  29 Nov 2021, 16:01

                  @JonB yes i am getting this error when the build process tries to link the object files together

                  and how do i check the whether it is being linked or not (i don't know how to check the linker stage output in qt)

                  (sorry for the late replay since i am a new user i can only post after 600 secs)

                  J Online
                  J Online
                  JonB
                  wrote on 29 Nov 2021, 16:01 last edited by JonB
                  #8

                  @seok said in Error:undefined reference to..:

                  (i don't know how to check the linker stage output in qt)

                  Look at the build/compile output pane in Qt Creator. You should be seeing it go past every time you build, so you really should be aware of it.

                  S 1 Reply Last reply 29 Nov 2021, 16:12
                  0
                  • J JonB
                    29 Nov 2021, 16:01

                    @seok said in Error:undefined reference to..:

                    (i don't know how to check the linker stage output in qt)

                    Look at the build/compile output pane in Qt Creator. You should be seeing it go past every time you build, so you really should be aware of it.

                    S Offline
                    S Offline
                    seok
                    wrote on 29 Nov 2021, 16:12 last edited by
                    #9

                    @JonB yes i tried build now and the problem lies at the linker stage

                    and i do have a .cpp file, which defines storage for the object, like Filter *myfilter without extern

                    J 1 Reply Last reply 29 Nov 2021, 16:25
                    0
                    • S seok
                      29 Nov 2021, 16:12

                      @JonB yes i tried build now and the problem lies at the linker stage

                      and i do have a .cpp file, which defines storage for the object, like Filter *myfilter without extern

                      J Online
                      J Online
                      JonB
                      wrote on 29 Nov 2021, 16:25 last edited by
                      #10

                      @seok said in Error:undefined reference to..:

                      @JonB yes i tried build now and the problem lies at the linker stage

                      As stated: look at the complete linker line issued, does it include the object file for filter, that would be the simplest thing to be missing?

                      S 1 Reply Last reply 29 Nov 2021, 16:34
                      1
                      • M Offline
                        M Offline
                        mchinand
                        wrote on 29 Nov 2021, 16:31 last edited by
                        #11

                        Is the source file definitely being compiled (look at the compile output panel)? Show your project file and tell us which file has that class.

                        1 Reply Last reply
                        0
                        • J JonB
                          29 Nov 2021, 16:25

                          @seok said in Error:undefined reference to..:

                          @JonB yes i tried build now and the problem lies at the linker stage

                          As stated: look at the complete linker line issued, does it include the object file for filter, that would be the simplest thing to be missing?

                          S Offline
                          S Offline
                          seok
                          wrote on 29 Nov 2021, 16:34 last edited by
                          #12

                          @JonB ok i will check

                          J.HilkJ 1 Reply Last reply 30 Nov 2021, 05:44
                          0
                          • J JonB
                            29 Nov 2021, 15:49

                            @jsulm
                            I didn't even know for sure whether at least some compilers would give an Undefined reference to just for a missing symbol in a file at compile time, like int z = something_undefined? But it seems this does only come from the linker, the compiler must say something else for that, like Undeclared ... instead?

                            J Offline
                            J Offline
                            jsulm
                            Lifetime Qt Champion
                            wrote on 30 Nov 2021, 05:35 last edited by
                            #13

                            @JonB Yes, all the compiler needs is to know the type of the symbol. Or, in case of forward declaration, only that it exists and is a data structure (class/struct). But the linker needs the actual definitions to be able to point to them in the binaries (for example it needs to know where a function is to be able to put the address to it where it is called).

                            https://forum.qt.io/topic/113070/qt-code-of-conduct

                            1 Reply Last reply
                            0
                            • S seok
                              29 Nov 2021, 16:34

                              @JonB ok i will check

                              J.HilkJ Offline
                              J.HilkJ Offline
                              J.Hilk
                              Moderators
                              wrote on 30 Nov 2021, 05:44 last edited by
                              #14

                              @seok are you sure your myfilter.h and myfilter.cpp are part of your project? As in listed in HEADERS += myfilter.h ?


                              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.

                              1 Reply Last reply
                              1
                              • S Offline
                                S Offline
                                seok
                                wrote on 21 Dec 2021, 14:42 last edited by
                                #15

                                @JonB sorry for updating this late i was not doing well

                                my problem solved by deleting the Filter myfilter (in the other .cpp file) and defining it again i don't know what was the problem ( i dint change anything just defined it again)

                                but i am really thankfull for all of your help

                                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