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. Include file not working. Getting "undefined reference to "
Forum Update on Monday, May 27th 2025

Include file not working. Getting "undefined reference to "

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 5 Posters 20.1k 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
    Count Vlad
    wrote on last edited by
    #1

    I'm trying to create a GUI and i'm having issues with some header files that the program needs and uses.

    If i click on the function in the main.cpp it takes me to the header file. But for some reason when i compile the program I get "undefined reference to " the function in main.cpp. Ive tried to add the path of the include folder where the header file in the .pro file but it didnt work. It seems to me that Qt sees the function but somehow it doesnt compile.

    Any suggestions? Thank you

    Paul ColbyP jsulmJ 2 Replies Last reply
    0
    • C Count Vlad

      I'm trying to create a GUI and i'm having issues with some header files that the program needs and uses.

      If i click on the function in the main.cpp it takes me to the header file. But for some reason when i compile the program I get "undefined reference to " the function in main.cpp. Ive tried to add the path of the include folder where the header file in the .pro file but it didnt work. It seems to me that Qt sees the function but somehow it doesnt compile.

      Any suggestions? Thank you

      Paul ColbyP Offline
      Paul ColbyP Offline
      Paul Colby
      wrote on last edited by
      #2

      Hi @Count-Vlad,

      An "undefined reference" error does not suggest a problem with the compiler finding the header (which declares the function), but more likely a problem with the compiler (or linker) not seeing the *.cpp file or object file containing the definition for the function.

      If the function is defined in your local project somewhere, make sure its *.cpp files is included in the *.pro file.

      If the function comes from some external library, make sure the library is included in the *.pro file.

      Cheers.

      1 Reply Last reply
      7
      • C Count Vlad

        I'm trying to create a GUI and i'm having issues with some header files that the program needs and uses.

        If i click on the function in the main.cpp it takes me to the header file. But for some reason when i compile the program I get "undefined reference to " the function in main.cpp. Ive tried to add the path of the include folder where the header file in the .pro file but it didnt work. It seems to me that Qt sees the function but somehow it doesnt compile.

        Any suggestions? Thank you

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @Count-Vlad What header file is it? One of the Qt header files?

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

        1 Reply Last reply
        2
        • yuvaramY Offline
          yuvaramY Offline
          yuvaram
          wrote on last edited by yuvaram
          #4

          HI @Count-Vlad

          you have mentioned that, *.h header file is added, but you have not specified *.cpp file or related library is included.
          Try to add *.cpp file in *.pro file. If same issue, delete build folder and re build the project.

          Yuvaram Aligeti
          Embedded Qt Developer
          : )

          1 Reply Last reply
          3
          • C Offline
            C Offline
            Count Vlad
            wrote on last edited by
            #5

            for some reason the compiler did not see the library that the header file needed. it was specified in the makefile but it didnt work.

            in the .pro file i added

            LIBS += -lmylib

            and that fixed the issue. Thank you for your help

            aha_1980A 1 Reply Last reply
            1
            • C Count Vlad

              for some reason the compiler did not see the library that the header file needed. it was specified in the makefile but it didnt work.

              in the .pro file i added

              LIBS += -lmylib

              and that fixed the issue. Thank you for your help

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

              @Count-Vlad: Glad you figured it out.

              LIBS += -lmylib is indeed the correct way to tell the linker to link to your lib. If you modify the Makefiles created by Qmake, your changes will be overwritten the next time qmake is run.

              So please mark this thread as solved now.

              Qt has to stay free or it will die.

              1 Reply Last reply
              2

              • Login

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