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. Linking a lib with QT on linux
Forum Updated to NodeBB v4.3 + New Features

Linking a lib with QT on linux

Scheduled Pinned Locked Moved Solved General and Desktop
22 Posts 4 Posters 3.4k 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.
  • mrjjM Offline
    mrjjM Offline
    mrjj
    Lifetime Qt Champion
    wrote on last edited by mrjj
    #2

    Hi and welcome to the forums

    But the same pro file works just with the
    #CONFIG += console
    enabled ?
    So we know the paths are 100% correct and do link it ?

    • and nothing seem to work

    Do you get any errors or it shows something in the compiler output ?

    or does it crash when you run it ?
    or it what way dont work ?

    1 Reply Last reply
    0
    • K Offline
      K Offline
      Keith Harville
      wrote on last edited by
      #3

      Thank you @mrjj for the replay!

      Even with enabling CONFIG += console still gives me the same error during compiling, which is undefined reference to "library function name"

      I included the library into the .pro file using the "Add a library ..." option, the library is copied to /usr/lib as well as (fw_console_api/make/linux)

      mrjjM 1 Reply Last reply
      0
      • K Keith Harville

        Thank you @mrjj for the replay!

        Even with enabling CONFIG += console still gives me the same error during compiling, which is undefined reference to "library function name"

        I included the library into the .pro file using the "Add a library ..." option, the library is copied to /usr/lib as well as (fw_console_api/make/linux)

        mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by mrjj
        #4

        @Keith-Harville
        hi
        ok. the sentence
        "tested the library using some command sample code which is fine."
        sounded like it did work in a console app ?

        "undefined reference " sounds like its not finding it so did you check the path carefully ?
        Also the filename is case sensitive so
        its 100% named
        fw_console_api
        ?
        written like that ?

        also try with plain
        LIBS += -L$$PWD/../../../fw_console_api/make/linux/ -lfw_console_api

        I wonder if it must be named lib in front but docs
        https://doc.qt.io/qt-5/third-party-libraries.html
        says
        " It is not necessary to specify the .lib extension, nor the lib prefix (on UNIX platforms)."

        You did compile the LIB with same compiler and Qt as your app ?

        Also is this a SO file or a static lib ? ( .a file)

        Update. Asked a clever friend of mine and since you are on linux, try renaming the so file to
        libfw_console_api
        and see if that helps.
        Also,
        if using a static library, PRE_TARGETDEPS += should be used.
        If the paths are correct then try
        nm and objdump to make sure the symbols were exported/present.

        1 Reply Last reply
        1
        • K Offline
          K Offline
          Keith Harville
          wrote on last edited by
          #5

          On the sentence "tested the library using some command sample code which is fine." I made a test app on command line to test the libfw_console_api.so library, and i was able to link the library and test the function calls successfully.

          I have checked the paths multiple times and copied the library in different places.. still no luck.

          since its SO library, I tired like your friend said "libfw_console_api" but I got "g++: error: libfw_console_api: No such file or directory"

          added .so libfw_console_api.so and now I am back to my original problem "undefined reference to "library function name"

          How do I do the nm and objdump to make sure the symbols

          jsulmJ 1 Reply Last reply
          0
          • K Keith Harville

            On the sentence "tested the library using some command sample code which is fine." I made a test app on command line to test the libfw_console_api.so library, and i was able to link the library and test the function calls successfully.

            I have checked the paths multiple times and copied the library in different places.. still no luck.

            since its SO library, I tired like your friend said "libfw_console_api" but I got "g++: error: libfw_console_api: No such file or directory"

            added .so libfw_console_api.so and now I am back to my original problem "undefined reference to "library function name"

            How do I do the nm and objdump to make sure the symbols

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

            @Keith-Harville said in Linking a lib with QT on linux:

            "g++: error: libfw_console_api: No such file or directory"

            Can you please show your pro file? Because the suggestion from @mrjj is the correct approach to link libraries with qmake.

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

            K 1 Reply Last reply
            3
            • jsulmJ jsulm

              @Keith-Harville said in Linking a lib with QT on linux:

              "g++: error: libfw_console_api: No such file or directory"

              Can you please show your pro file? Because the suggestion from @mrjj is the correct approach to link libraries with qmake.

              K Offline
              K Offline
              Keith Harville
              wrote on last edited by
              #7

              @jsulm @mrjj

              here is my full .pro

              QT += core gui charts
              #CONFIG += console
              
              greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
              
              TARGET = frameworkConsole
              TEMPLATE = app
              
              
              CONFIG += c++11 app_bundle
              #CONFIG -= app_bundle
              
              # The following define makes your compiler emit warnings if you use
              # any Qt feature that has been marked deprecated (the exact warnings
              # depend on your compiler). Please consult the documentation of the
              # deprecated API in order to know how to port your code away from it.
              DEFINES += QT_DEPRECATED_WARNINGS
              
              # You can also make your code fail to compile if it uses deprecated APIs.
              # In order to do so, uncomment the following line.
              # You can also select to disable deprecated APIs only up to a certain version of Qt.
              #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
              
              greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
              
              INCLUDEPATH += ../../../../inc
              
              SOURCES += \
                  ../../../src/countercontrol.cpp \
                  ../../../src/discoveryeventthread.cpp \
                  ../../../src/discoveryprogress.cpp \
                  ../../../src/dockbutton.cpp \
                  ../../../src/enablebutton.cpp \
                  ../../../src/frameworkConsole.cpp \
                  ../../../src/hdavconfig.cpp \
                  ../../../src/main.cpp \
                  ../../../src/moduleinfodialog.cpp \
                  ../../../src/nodetreeview.cpp \
                  ../../../src/playstopbutton.cpp
              
              HEADERS += \
                  ../../../src/countercontrol.h \
                  ../../../src/discoveryeventthread.h \
                  ../../../src/discoveryprogress.h \
                  ../../../src/dockbutton.h \
                  ../../../src/enablebutton.h \
                  ../../../src/frameworkConsole.h \
                  ../../../src/hdavconfig.h \
                  ../../../src/moduleinfodialog.h \
                  ../../../src/nodetreeview.h \
                  ../../../src/playstopbutton.h
              
              
              # Default rules for deployment.
              qnx: target.path = /tmp/$${TARGET}/bin
              else: unix:!android: target.path = /opt/$${TARGET}/bin
              !isEmpty(target.path): INSTALLS += target
              
              unix:!macx: LIBS += -L$$PWD/../ -lfw_console_api
              
              INCLUDEPATH += $$PWD/../
              DEPENDPATH += $$PWD/../
              
              1 Reply Last reply
              0
              • K Offline
                K Offline
                Keith Harville
                wrote on last edited by
                #8

                I have created a small test app and made one call to the library as well.

                I can send you the full source for test app as well.

                1 Reply Last reply
                1
                • mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #9

                  Hi
                  If libray is compiled with same compiler and all that is in order, then
                  its most of the time just a path issue.

                  However, that is hard to test so the mini sample is a good thing.

                  Could you upload to say
                  https://wetransfer.com/
                  and use the get link
                  alt text

                  and paste link here so we could try run the project ?

                  1 Reply Last reply
                  0
                  • K Offline
                    K Offline
                    Keith Harville
                    wrote on last edited by
                    #10

                    here is a link to the testApp.zip it should include everything

                    https://we.tl/t-TcnN3DZR7b

                    mrjjM 1 Reply Last reply
                    0
                    • K Keith Harville

                      here is a link to the testApp.zip it should include everything

                      https://we.tl/t-TcnN3DZR7b

                      mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by
                      #11

                      @Keith-Harville
                      Link works.
                      However, its seems the cpp for libfw_console_api.so is not included ?

                      So we also need to know the gcc version used to compile the test app.
                      Just we are sure to use ca. the same version.

                      I assume no Qt was used in libfw_console_api so Qt version is not important.

                      1 Reply Last reply
                      1
                      • Christian EhrlicherC Offline
                        Christian EhrlicherC Offline
                        Christian Ehrlicher
                        Lifetime Qt Champion
                        wrote on last edited by
                        #12

                        @mrjj said in Linking a lib with QT on linux:

                        So we also need to know the gcc version used to compile the test app.

                        And the complete error message.

                        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                        Visit the Qt Academy at https://academy.qt.io/catalog

                        1 Reply Last reply
                        1
                        • K Offline
                          K Offline
                          Keith Harville
                          wrote on last edited by
                          #13

                          gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.12)

                          1 Reply Last reply
                          0
                          • K Offline
                            K Offline
                            Keith Harville
                            wrote on last edited by
                            #14

                            undefined reference to `fwConsole_initConsoleHeader(FW_CONSOLE_HEADER*)'

                            1 Reply Last reply
                            0
                            • Christian EhrlicherC Offline
                              Christian EhrlicherC Offline
                              Christian Ehrlicher
                              Lifetime Qt Champion
                              wrote on last edited by
                              #15

                              Since it's a C library you must make sure that the compiler also interpret your header as C ->

                              extern "C"
                              {
                              #include "fw_console_api.h"
                              }
                              

                              Or fix the header so it's not needed for every include of it.

                              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                              Visit the Qt Academy at https://academy.qt.io/catalog

                              mrjjM 1 Reply Last reply
                              4
                              • K Offline
                                K Offline
                                Keith Harville
                                wrote on last edited by
                                #16

                                Thank you so much, that fixed it

                                1 Reply Last reply
                                0
                                • Christian EhrlicherC Christian Ehrlicher

                                  Since it's a C library you must make sure that the compiler also interpret your header as C ->

                                  extern "C"
                                  {
                                  #include "fw_console_api.h"
                                  }
                                  

                                  Or fix the header so it's not needed for every include of it.

                                  mrjjM Offline
                                  mrjjM Offline
                                  mrjj
                                  Lifetime Qt Champion
                                  wrote on last edited by
                                  #17

                                  @Christian-Ehrlicher
                                  Hi
                                  You are so fast. :)
                                  What did you run on it too see it was a C lib ?
                                  or just be looking in the .h file ?

                                  1 Reply Last reply
                                  0
                                  • Christian EhrlicherC Offline
                                    Christian EhrlicherC Offline
                                    Christian Ehrlicher
                                    Lifetime Qt Champion
                                    wrote on last edited by
                                    #18

                                    @mrjj said in Linking a lib with QT on linux:

                                    What did you run on it too see it was a C lib ?

                                    I got a linker error, looked at the exports and they looked like plain C exports. Then the idea with the wrong symbols was there :)

                                    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                                    Visit the Qt Academy at https://academy.qt.io/catalog

                                    mrjjM 1 Reply Last reply
                                    2
                                    • Christian EhrlicherC Christian Ehrlicher

                                      @mrjj said in Linking a lib with QT on linux:

                                      What did you run on it too see it was a C lib ?

                                      I got a linker error, looked at the exports and they looked like plain C exports. Then the idea with the wrong symbols was there :)

                                      mrjjM Offline
                                      mrjjM Offline
                                      mrjj
                                      Lifetime Qt Champion
                                      wrote on last edited by
                                      #19

                                      @Christian-Ehrlicher
                                      Ok, where did you look at the exports ?
                                      With objdump or ?
                                      Im asking as i want to learn. Since you knew so fast and i was still looking at it :)

                                      1 Reply Last reply
                                      0
                                      • Christian EhrlicherC Offline
                                        Christian EhrlicherC Offline
                                        Christian Ehrlicher
                                        Lifetime Qt Champion
                                        wrote on last edited by
                                        #20

                                        @mrjj said in Linking a lib with QT on linux:

                                        With objdump or ?

                                        Yes, "objdump -T" - take a look at the libfw_console_api.so output and you will notice that they're plain C functions - they are not annotated.

                                        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                                        Visit the Qt Academy at https://academy.qt.io/catalog

                                        mrjjM 1 Reply Last reply
                                        2
                                        • Christian EhrlicherC Christian Ehrlicher

                                          @mrjj said in Linking a lib with QT on linux:

                                          With objdump or ?

                                          Yes, "objdump -T" - take a look at the libfw_console_api.so output and you will notice that they're plain C functions - they are not annotated.

                                          mrjjM Offline
                                          mrjjM Offline
                                          mrjj
                                          Lifetime Qt Champion
                                          wrote on last edited by mrjj
                                          #21

                                          @Christian-Ehrlicher
                                          Thank you
                                          Its handy to know. goes on my of list of things to try when you get undefined's and
                                          checked path many times :=)

                                          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