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. how to fix linker error in eclipse on linux
QtWS25 Last Chance

how to fix linker error in eclipse on linux

Scheduled Pinned Locked Moved Solved General and Desktop
58 Posts 3 Posters 10.7k 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.
  • J jsulm
    23 Feb 2022, 07:06

    @micha_eleric said in how to fix linker error in eclipse on linux:

    i cant find any qmainwindow, mainwindow, anything close to mainwindow in /usr/lib/x86_64-linux-gnu/

    Of course not. QMainWindow is part of widgets module as you can easilly see in the documentation: https://doc.qt.io/qt-5/qmainwindow.html (qmake: QT += widgets)
    That means you should look for libQt5Widgets.so in /usr/lib/x86_64-linux-gnu.
    And "surprisingly" it is there in your own list of libs: /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5

    M Offline
    M Offline
    micha_eleric
    wrote on 23 Feb 2022, 07:16 last edited by
    #49

    @jsulm g++ -L/usr/lib/x86_64-linux-gnu -L/usr -L/ -L/usr/lib -L/usr/lib/x86_64-linux-gnu/qt5 -L/usr/lib/qt5 -o "GUI2" ./src/CGUI.o ./src/Main.o /usr/lib/x86_64-linux-gnu/libQtGui.so /usr/lib/x86_64-linux-gnu/libQt5Widgets.so
    /usr/bin/ld: ./src/CGUI.o: in function CGUI::CGUI(QWidget*)': /home/michaeleric/eclipse-workspace/GUI2/Debug/../src/CGUI.cpp:10: undefined reference to vtable for CGUI'
    /usr/bin/ld: /home/michaeleric/eclipse-workspace/GUI2/Debug/../src/CGUI.cpp:10: undefined reference to vtable for CGUI' /usr/bin/ld: ./src/CGUI.o: in function CGUI::~CGUI()':
    /home/michaeleric/eclipse-workspace/GUI2/Debug/../src/CGUI.cpp:15: undefined reference to vtable for CGUI' /usr/bin/ld: /home/michaeleric/eclipse-workspace/GUI2/Debug/../src/CGUI.cpp:15: undefined reference to vtable for CGUI'

    J 1 Reply Last reply 23 Feb 2022, 07:19
    0
    • M micha_eleric
      23 Feb 2022, 07:16

      @jsulm g++ -L/usr/lib/x86_64-linux-gnu -L/usr -L/ -L/usr/lib -L/usr/lib/x86_64-linux-gnu/qt5 -L/usr/lib/qt5 -o "GUI2" ./src/CGUI.o ./src/Main.o /usr/lib/x86_64-linux-gnu/libQtGui.so /usr/lib/x86_64-linux-gnu/libQt5Widgets.so
      /usr/bin/ld: ./src/CGUI.o: in function CGUI::CGUI(QWidget*)': /home/michaeleric/eclipse-workspace/GUI2/Debug/../src/CGUI.cpp:10: undefined reference to vtable for CGUI'
      /usr/bin/ld: /home/michaeleric/eclipse-workspace/GUI2/Debug/../src/CGUI.cpp:10: undefined reference to vtable for CGUI' /usr/bin/ld: ./src/CGUI.o: in function CGUI::~CGUI()':
      /home/michaeleric/eclipse-workspace/GUI2/Debug/../src/CGUI.cpp:15: undefined reference to vtable for CGUI' /usr/bin/ld: /home/michaeleric/eclipse-workspace/GUI2/Debug/../src/CGUI.cpp:15: undefined reference to vtable for CGUI'

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 23 Feb 2022, 07:19 last edited by
      #50

      @micha_eleric said in how to fix linker error in eclipse on linux:

      /usr/bin/ld: ./src/CGUI.o: in function CGUI::CGUI(QWidget*)': /home/michaeleric/eclipse-workspace/GUI2/Debug/../src/CGUI.cpp:10: undefined reference tovtable for CGUI'

      This is now another problem.
      Classes which subclass QObject need moc tool (see https://doc.qt.io/qt-5/moc.html for more details). You can of course do that manually somehow.
      But I would strongly recommend to use a proper build tool, either qmake or CMake. Both will call moc for your.

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

      M 2 Replies Last reply 23 Feb 2022, 07:38
      1
      • J jsulm
        23 Feb 2022, 07:19

        @micha_eleric said in how to fix linker error in eclipse on linux:

        /usr/bin/ld: ./src/CGUI.o: in function CGUI::CGUI(QWidget*)': /home/michaeleric/eclipse-workspace/GUI2/Debug/../src/CGUI.cpp:10: undefined reference tovtable for CGUI'

        This is now another problem.
        Classes which subclass QObject need moc tool (see https://doc.qt.io/qt-5/moc.html for more details). You can of course do that manually somehow.
        But I would strongly recommend to use a proper build tool, either qmake or CMake. Both will call moc for your.

        M Offline
        M Offline
        micha_eleric
        wrote on 23 Feb 2022, 07:38 last edited by
        #51

        @jsulm thank you

        1 Reply Last reply
        0
        • J jsulm
          23 Feb 2022, 07:19

          @micha_eleric said in how to fix linker error in eclipse on linux:

          /usr/bin/ld: ./src/CGUI.o: in function CGUI::CGUI(QWidget*)': /home/michaeleric/eclipse-workspace/GUI2/Debug/../src/CGUI.cpp:10: undefined reference tovtable for CGUI'

          This is now another problem.
          Classes which subclass QObject need moc tool (see https://doc.qt.io/qt-5/moc.html for more details). You can of course do that manually somehow.
          But I would strongly recommend to use a proper build tool, either qmake or CMake. Both will call moc for your.

          M Offline
          M Offline
          micha_eleric
          wrote on 23 Feb 2022, 07:40 last edited by
          #52

          @jsulm

          This is now another problem.
          Classes which subclass QObject need moc tool (see https://doc.qt.io/qt-5/moc.html for more details). You can of course do that manually somehow.
          But I would strongly recommend to use a proper build tool, either qmake or CMake. Both will call moc for your.

          and not part of the install

          J 1 Reply Last reply 23 Feb 2022, 07:45
          0
          • M micha_eleric
            23 Feb 2022, 07:40

            @jsulm

            This is now another problem.
            Classes which subclass QObject need moc tool (see https://doc.qt.io/qt-5/moc.html for more details). You can of course do that manually somehow.
            But I would strongly recommend to use a proper build tool, either qmake or CMake. Both will call moc for your.

            and not part of the install

            J Offline
            J Offline
            jsulm
            Lifetime Qt Champion
            wrote on 23 Feb 2022, 07:45 last edited by
            #53

            @micha_eleric said in how to fix linker error in eclipse on linux:

            and not part of the install

            Do you mean moc? If you properly installed Qt development packages then it should be there.
            On my Ubuntu: /usr/bin/moc

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

            M 1 Reply Last reply 23 Feb 2022, 08:04
            0
            • J jsulm
              23 Feb 2022, 07:45

              @micha_eleric said in how to fix linker error in eclipse on linux:

              and not part of the install

              Do you mean moc? If you properly installed Qt development packages then it should be there.
              On my Ubuntu: /usr/bin/moc

              M Offline
              M Offline
              micha_eleric
              wrote on 23 Feb 2022, 08:04 last edited by
              #54

              @jsulm using eclipse

              1 Reply Last reply
              0
              • M micha_eleric
                22 Feb 2022, 00:57

                using eclipse on linux
                error, i am mostly sure is an eclipse issue, and not a programming issue.

                g++ -L/usr/include/qt4 -L/usr/include/qt4/QtSerialPort -L/usr/include/qt4/QtGui -o "GUI2" ./src/CGUI.o ./src/Main.o
                /usr/bin/ld: ./src/CGUI.o: in function CGUI::CGUI()': /home/michaeleric/eclipse-workspace/GUI2/Debug/../src/CGUI.cpp:10: undefined reference to QMainWindow::QMainWindow(QWidget*, QFlagsQt::WindowType)'
                /usr/bin/ld: /home/michaeleric/eclipse-workspace/GUI2/Debug/../src/CGUI.cpp:10: undefined reference to vtable for CGUI' /usr/bin/ld: /home/michaeleric/eclipse-workspace/GUI2/Debug/../src/CGUI.cpp:10: undefined reference to vtable for CGUI'
                /usr/bin/ld: ./src/CGUI.o: in function CGUI::~CGUI()': /home/michaeleric/eclipse-workspace/GUI2/Debug/../src/CGUI.cpp:15: undefined reference to vtable for CGUI'
                /usr/bin/ld: /home/michaeleric/eclipse-workspace/GUI2/Debug/../src/CGUI.cpp:15: undefined reference to vtable for CGUI' /usr/bin/ld: /home/michaeleric/eclipse-workspace/GUI2/Debug/../src/CGUI.cpp:15: undefined reference to QMainWindow::~QMainWindow()'
                /usr/bin/ld: ./src/Main.o: in function main': /home/michaeleric/eclipse-workspace/GUI2/Debug/../src/Main.cpp:14: undefined reference to QApplication::QApplication(int&, char**, int)'
                /usr/bin/ld: /home/michaeleric/eclipse-workspace/GUI2/Debug/../src/Main.cpp:17: undefined reference to QApplication::exec()' /usr/bin/ld: /home/michaeleric/eclipse-workspace/GUI2/Debug/../src/Main.cpp:14: undefined reference to QApplication::~QApplication()'
                /usr/bin/ld: /home/michaeleric/eclipse-workspace/GUI2/Debug/../src/Main.cpp:14: undefined reference to `QApplication::~QApplication()'
                collect2: error: ld returned 1 exit status
                make: *** [makefile:47: GUI2] Error 1

                based on https://forum.qt.io/topic/101400/qt-with-eclipse-c/5 , i added QtCore and QtWidgets, even though there were no errors with #include<>. same errors from compile.

                https://stackoverflow.com/questions/6478317/eclipse-undefined-reference says it is a linker error

                under Properties->C/C++ Build->Settings->Tool Settings->GCC C++ Linker->command: g++

                under Properties->C/C++ Build->Settings->Tool Settings->GCC C++ Linker->Libraries->Libraries (-l) [nothing]

                under Properties->C/C++ Build->Settings->Tool Settings->GCC C++ Linker->Libraries->Libraries search path (-L) /usr/include/qt4 /usr/include/qt4/QtWidgets /usr/include/qt4/QtCore /usr/include/qt4/QtSerialPort /usr/include/qt4/QtGui

                under Properties->C/C++ Build->Settings->Tool Settings->GCC C++ Linker->Miscellaneous->Linker flags [nothing]

                under Properties->C/C++ Build->Settings->Tool Settings->GCC C++ Linker->Miscellaneous->Other options (-Xlinker [option]) [nothing]

                under Properties->C/C++ Build->Settings->Tool Settings->GCC C++ Linker->Miscellaneous->Other objects [nothing]

                under Properties->C/C++ Build->Settings->Tool Settings->GCC C++ Linker->Shared Library Settings [nothing][nothing][nothing][nothing]

                what is suppose to be added, and where?

                if:
                under Properties->C/C++ Build->Settings->Tool Settings->GCC C++ Linker->Libraries->Libraries (-l) /usr/include/qt4/QtGui
                error:
                /usr/bin/ld: cannot find -l/usr/include/qt4/QtGui

                if:
                under Properties->C/C++ Build->Settings->Tool Settings->GCC C++ Linker->Miscellaneous->Other options (-Xlinker [option]) /usr/include/qt4/QtGui
                error:
                /usr/bin/ld: cannot find /usr/include/qt4/QtGui: file format not recognized

                if:
                under Properties->C/C++ Build->Settings->Tool Settings->GCC C++ Linker->Miscellaneous->Other objects /usr/include/qt4/QtGui
                error:
                /usr/bin/ld: cannot find /usr/include/qt4/QtGui: file format not recognized

                if it is a virtual function that has to be defined, then what would it be, other than constructor/destructor?


                answer:
                deleting:
                under Properties->C/C++ Build->Settings->Tool Settings->GCC C++ Linker->Libraries->Libraries search path (-L) /usr/include/qt4 /usr/include/qt4/QtWidgets /usr/include/qt4/QtCore /usr/include/qt4/QtSerialPort /usr/include/qt4/QtGui, did nothing, no new errors, nothing with previous errors

                under Properties->C/C++ Build->Settings->Tool Settings->GCC C++ Linker->Miscellaneous->Other objects /usr/lib/x86_64-linux-gnu/libQtGui.so
                fixed errors, exposed new errors

                M Offline
                M Offline
                micha_eleric
                wrote on 23 Feb 2022, 08:04 last edited by
                #55

                @micha_eleric said in how to fix linker error in eclipse on linux:

                using eclipse on linux
                error, i am mostly sure is an eclipse issue, and not a programming issue.

                1 Reply Last reply
                0
                • M micha_eleric
                  23 Feb 2022, 00:02

                  @JonB for me, find /usr/lib -name'*Qt5 *', anr find /usr/lib -name *Qt5 * had same results. [note] no space between 5 and *

                  J Offline
                  J Offline
                  JonB
                  wrote on 23 Feb 2022, 09:45 last edited by JonB
                  #56

                  @micha_eleric said in how to fix linker error in eclipse on linux:

                  @JonB for me, find /usr/lib -name'*Qt5 *', anr find /usr/lib -name *Qt5 * had same results. [note] no space between 5 and *

                  Not if you did as I carefully stated and had any file with Qt5 in its name in the directory where you were when you typed in that find command, as I explained.....
                  @JonB said in how to fix linker error in eclipse on linux:

                  P.S.
                  If anyone does not believe me: before running the command do a touch Qt5 in the directory you run find /usr/lib -name '*Qt5*' versus find /usr/lib -name *Qt5* from., and compare the results...

                  Did you do that touch or not?

                  M 1 Reply Last reply 24 Feb 2022, 22:16
                  1
                  • J JonB
                    23 Feb 2022, 09:45

                    @micha_eleric said in how to fix linker error in eclipse on linux:

                    @JonB for me, find /usr/lib -name'*Qt5 *', anr find /usr/lib -name *Qt5 * had same results. [note] no space between 5 and *

                    Not if you did as I carefully stated and had any file with Qt5 in its name in the directory where you were when you typed in that find command, as I explained.....
                    @JonB said in how to fix linker error in eclipse on linux:

                    P.S.
                    If anyone does not believe me: before running the command do a touch Qt5 in the directory you run find /usr/lib -name '*Qt5*' versus find /usr/lib -name *Qt5* from., and compare the results...

                    Did you do that touch or not?

                    M Offline
                    M Offline
                    micha_eleric
                    wrote on 24 Feb 2022, 22:16 last edited by
                    #57

                    @JonB touch did something different, but not touch *Qt5 *, and touch '*Qt5 *'

                    J 1 Reply Last reply 25 Feb 2022, 10:05
                    0
                    • M micha_eleric
                      24 Feb 2022, 22:16

                      @JonB touch did something different, but not touch *Qt5 *, and touch '*Qt5 *'

                      J Offline
                      J Offline
                      JonB
                      wrote on 25 Feb 2022, 10:05 last edited by JonB
                      #58

                      @micha_eleric said in how to fix linker error in eclipse on linux:

                      but not touch *Qt5 *, and touch '*Qt5 *'

                      Of course not, if you understand wildcards you would know that could not work, and never what I said.

                      I could not have been clearer, I said touch Qt5 would change the behaviour of find ... -name *Qt5*, but not of find ... -name '*Qt5*'. Hence all i was saying is that find with a wildcard should always put the wildcard part inside quotes.

                      1 Reply Last reply
                      2

                      58/58

                      25 Feb 2022, 10:05

                      • Login

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