Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Installation and Deployment
  4. [SOLVED] Link error - Undefined reference
QtWS25 Last Chance

[SOLVED] Link error - Undefined reference

Scheduled Pinned Locked Moved Solved Installation and Deployment
link errorcompilation
9 Posts 3 Posters 6.9k 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.
  • C Offline
    C Offline
    Calivernon
    wrote on 12 Jan 2016, 22:45 last edited by Calivernon
    #1

    Hello, I am a new QTcreator user and I can't compile a simple program,

    I have my class defined and implemented in polynomial.h and polynomial.cpp
    I have also main.cpp which (is supposed to) instantiate my class TPolynomial.

    When I build I get the error:
    undefined reference to TPolynomial<int>::TPolynomial()

    I have found similar topic so I tried to clean, run qmake and rebuild, Qt creates main.o and polynomial.o, they both are in the "build folder" with the make file but it doesn't work, it seems not to find the polynomial.o?

    And when I write the implementation of my class in the header it works, so the problem is that Qt doesn't look for in the good folder.

    Do I have to specify a folder somewhere in the options?
    I don't think because all the files are in the same folder?

    Thanks.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 12 Jan 2016, 22:51 last edited by
      #2

      Hi and welcome to devnet,

      No, it's not a problem of Qt, you are implementing a template class. See the C++ Super FAQ about the template

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

      C 1 Reply Last reply 12 Jan 2016, 23:49
      0
      • S SGaist
        12 Jan 2016, 22:51

        Hi and welcome to devnet,

        No, it's not a problem of Qt, you are implementing a template class. See the C++ Super FAQ about the template

        C Offline
        C Offline
        Calivernon
        wrote on 12 Jan 2016, 23:49 last edited by
        #3

        @SGaist

        Thank you for the link.

        Under the implementation of the template method, I tried to add the line:
        "template void freePolynomial<int>();"

        I get the error message:
        "variable or field 'freePolynomial' declared void"

        Then I tried to add "external" before the declaration of the method in the header,
        I get the error message:
        "storage class specified for 'freePolynomial'"

        So I have no idea what to do!

        J 1 Reply Last reply 13 Jan 2016, 05:57
        0
        • C Calivernon
          12 Jan 2016, 23:49

          @SGaist

          Thank you for the link.

          Under the implementation of the template method, I tried to add the line:
          "template void freePolynomial<int>();"

          I get the error message:
          "variable or field 'freePolynomial' declared void"

          Then I tried to add "external" before the declaration of the method in the header,
          I get the error message:
          "storage class specified for 'freePolynomial'"

          So I have no idea what to do!

          J Offline
          J Offline
          jsulm
          Lifetime Qt Champion
          wrote on 13 Jan 2016, 05:57 last edited by
          #4

          @Calivernon Did you check the link provided by SGaist? Templates MUST be defined in the header file. So, you cannot put the definition in a .cpp file.

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

          C 1 Reply Last reply 13 Jan 2016, 15:33
          0
          • J jsulm
            13 Jan 2016, 05:57

            @Calivernon Did you check the link provided by SGaist? Templates MUST be defined in the header file. So, you cannot put the definition in a .cpp file.

            C Offline
            C Offline
            Calivernon
            wrote on 13 Jan 2016, 15:33 last edited by
            #5

            @jsulm

            Hi, yes I tried what they say in the link but I got an error message.
            I wrote in my last message what I did and the message I got.

            1 Reply Last reply
            0
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 13 Jan 2016, 21:59 last edited by
              #6

              Can you share your code ? Without it it's pretty much Crystal Ball Debugging.

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

              C 1 Reply Last reply 16 Jan 2016, 23:00
              0
              • S SGaist
                13 Jan 2016, 21:59

                Can you share your code ? Without it it's pretty much Crystal Ball Debugging.

                C Offline
                C Offline
                Calivernon
                wrote on 16 Jan 2016, 23:00 last edited by
                #7

                @SGaist

                Hello sorry but I am writing my class in the header, it's a pity but it works.
                If I have time I try again.
                Thanks

                1 Reply Last reply
                0
                • C Offline
                  C Offline
                  Calivernon
                  wrote on 24 Jan 2016, 14:23 last edited by
                  #8

                  It's alright, I started a new project and I don't really know why but it works now.
                  Thanks guys.

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on 24 Jan 2016, 20:53 last edited by
                    #9

                    That's a good news but still a strange mystery…

                    By the way, no need to modify the thread title, you can mark it as solved using the "Topic Tool" button :)

                    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

                    • Login

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