Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. TEMPLATE = lib ?

TEMPLATE = lib ?

Scheduled Pinned Locked Moved Unsolved C++ Gurus
7 Posts 2 Posters 612 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.
  • A Offline
    A Offline
    Anonymous_Banned275
    wrote on last edited by
    #1

    Duplicate post

    I am still looking for an answer...

    My Qt example "terminal" runs fine when TEMPLATE = app.
    When I change to TEMPLATE=lib my MAIN WINDOW fails with "undefined reference ".

    I have checked all my headers etc many times and there are NO compiler errors.
    It is definitely a linker error and I cannot find it.

    Here is my CURRENT question:

    the "terminal " project contains THREE header files ,
    do I have to add ALL of them to the class where the "terminal" library is used ?

    I did , and I still get same "undefined reference" , BUT only on the main class - the other classes do not generate any errors - compiler or linker.
    BUT at this point I need the main class / object to link.

    The others SHOULD work since it runs just fine as TEMPLATE= app.

    PS
    The "terminal" runs main (parent) and "pop up" dialogs, I did try to delete the dialogs but it did not go well - too many dependencies..

    JonBJ 1 Reply Last reply
    0
    • A Anonymous_Banned275

      Duplicate post

      I am still looking for an answer...

      My Qt example "terminal" runs fine when TEMPLATE = app.
      When I change to TEMPLATE=lib my MAIN WINDOW fails with "undefined reference ".

      I have checked all my headers etc many times and there are NO compiler errors.
      It is definitely a linker error and I cannot find it.

      Here is my CURRENT question:

      the "terminal " project contains THREE header files ,
      do I have to add ALL of them to the class where the "terminal" library is used ?

      I did , and I still get same "undefined reference" , BUT only on the main class - the other classes do not generate any errors - compiler or linker.
      BUT at this point I need the main class / object to link.

      The others SHOULD work since it runs just fine as TEMPLATE= app.

      PS
      The "terminal" runs main (parent) and "pop up" dialogs, I did try to delete the dialogs but it did not go well - too many dependencies..

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @AnneRanch
      I did explain in your other post that this has nothing to do with header files or compilation.

      If you showed the full link command line for each of the two cases (app/lib) we ought be able to spot where one of the two fails to link with the necessary .o file which generates the "undefined reference".

      A 1 Reply Last reply
      1
      • JonBJ JonB

        @AnneRanch
        I did explain in your other post that this has nothing to do with header files or compilation.

        If you showed the full link command line for each of the two cases (app/lib) we ought be able to spot where one of the two fails to link with the necessary .o file which generates the "undefined reference".

        A Offline
        A Offline
        Anonymous_Banned275
        wrote on last edited by
        #3

        @JonB Can you be specific ?
        What "command line" are you looking for ?

        JonBJ 1 Reply Last reply
        0
        • A Anonymous_Banned275

          @JonB Can you be specific ?
          What "command line" are you looking for ?

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #4

          @AnneRanch
          Probably the final one each time you have to build. They will both start with ld (or /bin/ld or whatever) I think, though it might be gcc/g++/clang++ as a wrapper. The line will contain some filename.o files, and it won't have any .cpps. In the app case it will be building your executable, in the lib case it will be building some *.so file, the library.

          We should find that the one which gives an error does not contain your, I forget exactly what, but some ...BLUETOOTH...terminal.o file, while the one which works does contain that. Or, one of them has your main.owhile the other does not. One of those combinations should be why you get the "undefined reference" from the linker.

          Hang on, I'm looking at your post https://forum.qt.io/topic/155810/undefined-reference-again-discussion/8

          clang++ -ccc-gcc-name g++ -Wl,-rpath,/home/nov25-1/Qt/5.15.2/gcc_64/lib -shared -Wl,-soname,libterminal.so.1 -o libterminal.so.1.0.0 main.o settingsdialog.o console.o terminal_ORIGINAL_mainwindow.o qrc_terminal.o moc_settingsdialog.o moc_console.o moc_terminal_ORIGINAL_mainwindow.o /home/nov25-1/Qt/5.15.2/gcc_64/lib/libQt5Widgets.so
          
          /home/nov25-1/Qt/5.15.2/gcc_64/lib/libQt5Gui.so /home/nov25-1/Qt/5.15.2/gcc_64/lib/libQt5SerialPort.so /home/nov25-1/Qt/5.15.2/gcc_64/lib/libQt5Core.so -lGL -lpthread
          

          OK, that is your -o libterminal.so.1.0.0, for the library, the lib case, and that works. It has both mainwindow.o and terminal_ORIGINAL_mainwindow.o, that is good.

          Now we need to see the equivalent link line when you build for app and you get the "Undefined error" message from the linker. I think it will have mainwindow.o but not terminal_ORIGINAL_mainwindow.o, and that is bad.

          Hmm, I see you say

          My Qt example "terminal" runs fine when TEMPLATE = app.

          When I change to TEMPLATE=lib my MAIN WINDOW fails with "undefined reference ".

          But I think that other thread shows tour lib case works? I'm lost now :)

          A 1 Reply Last reply
          1
          • JonBJ JonB

            @AnneRanch
            Probably the final one each time you have to build. They will both start with ld (or /bin/ld or whatever) I think, though it might be gcc/g++/clang++ as a wrapper. The line will contain some filename.o files, and it won't have any .cpps. In the app case it will be building your executable, in the lib case it will be building some *.so file, the library.

            We should find that the one which gives an error does not contain your, I forget exactly what, but some ...BLUETOOTH...terminal.o file, while the one which works does contain that. Or, one of them has your main.owhile the other does not. One of those combinations should be why you get the "undefined reference" from the linker.

            Hang on, I'm looking at your post https://forum.qt.io/topic/155810/undefined-reference-again-discussion/8

            clang++ -ccc-gcc-name g++ -Wl,-rpath,/home/nov25-1/Qt/5.15.2/gcc_64/lib -shared -Wl,-soname,libterminal.so.1 -o libterminal.so.1.0.0 main.o settingsdialog.o console.o terminal_ORIGINAL_mainwindow.o qrc_terminal.o moc_settingsdialog.o moc_console.o moc_terminal_ORIGINAL_mainwindow.o /home/nov25-1/Qt/5.15.2/gcc_64/lib/libQt5Widgets.so
            
            /home/nov25-1/Qt/5.15.2/gcc_64/lib/libQt5Gui.so /home/nov25-1/Qt/5.15.2/gcc_64/lib/libQt5SerialPort.so /home/nov25-1/Qt/5.15.2/gcc_64/lib/libQt5Core.so -lGL -lpthread
            

            OK, that is your -o libterminal.so.1.0.0, for the library, the lib case, and that works. It has both mainwindow.o and terminal_ORIGINAL_mainwindow.o, that is good.

            Now we need to see the equivalent link line when you build for app and you get the "Undefined error" message from the linker. I think it will have mainwindow.o but not terminal_ORIGINAL_mainwindow.o, and that is bad.

            Hmm, I see you say

            My Qt example "terminal" runs fine when TEMPLATE = app.

            When I change to TEMPLATE=lib my MAIN WINDOW fails with "undefined reference ".

            But I think that other thread shows tour lib case works? I'm lost now :)

            A Offline
            A Offline
            Anonymous_Banned275
            wrote on last edited by
            #5

            @JonB I have TWO modified "terminal " projects - they both work as TEMPLATE = app.
            To make sure , I run them as stand-alone projects, not as part of the "subdirs".

            The less modified original "terminal" does not work as TEMPLATE=lib.

            Can you comment on the question about including ALL headers ?

            JonBJ 1 Reply Last reply
            0
            • A Anonymous_Banned275

              @JonB I have TWO modified "terminal " projects - they both work as TEMPLATE = app.
              To make sure , I run them as stand-alone projects, not as part of the "subdirs".

              The less modified original "terminal" does not work as TEMPLATE=lib.

              Can you comment on the question about including ALL headers ?

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by JonB
              #6

              @AnneRanch said in TEMPLATE = lib ?:

              The less modified original "terminal" does not work as TEMPLATE=lib.

              Then if you wanted help with that it is the one whose ld/g++/clang++ -o something.so link line generates an "Undefined reference to ..." error.

              I can only say that if you get an "Undefined reference" error from the linker, which is what I understand you to be asking about:

              When I change to TEMPLATE=lib my MAIN WINDOW fails with "undefined reference ".
              It is definitely a linker error and I cannot find it.

              that is not to do with you including or not including .h files in .cpp files. It is to do with your code actually calling a function in another .o file and that not being passed to the linker to resolve.

              A 1 Reply Last reply
              1
              • JonBJ JonB

                @AnneRanch said in TEMPLATE = lib ?:

                The less modified original "terminal" does not work as TEMPLATE=lib.

                Then if you wanted help with that it is the one whose ld/g++/clang++ -o something.so link line generates an "Undefined reference to ..." error.

                I can only say that if you get an "Undefined reference" error from the linker, which is what I understand you to be asking about:

                When I change to TEMPLATE=lib my MAIN WINDOW fails with "undefined reference ".
                It is definitely a linker error and I cannot find it.

                that is not to do with you including or not including .h files in .cpp files. It is to do with your code actually calling a function in another .o file and that not being passed to the linker to resolve.

                A Offline
                A Offline
                Anonymous_Banned275
                wrote on last edited by
                #7

                @JonB said in TEMPLATE = lib ?:

                that is not to do with you including or not including .h files in .cpp files.

                That has been discussed and concluded TRUE.
                Let's move on...

                It is to do with your code actually calling a function in another .o file and that not being passed to the linker to resolve.

                That is NOT the case - I have described how I use "add library"
                to add it to subproject .pro file - who is using it.

                Let's move on...

                I suspect the link to .so IS THE issue...

                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