Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Qt5 Compile with an error "undefined reference" when linking static libraries or dynamic libraries

Qt5 Compile with an error "undefined reference" when linking static libraries or dynamic libraries

Scheduled Pinned Locked Moved Solved Mobile and Embedded
10 Posts 4 Posters 7.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.
  • A Offline
    A Offline
    Alex_wang
    wrote on 1 Aug 2017, 03:43 last edited by
    #1

    Qt5 linked the static libraries which have defined by this function,but the error still appear:

    qt_odin.o:‘QOdinMsg::MsgQCreate()’ :
    qt_odin.cpp.text+0x14):function ‘od_msg_create_fix_trans(char const*, unsigned int, unsigned int, unsigned int) ’  undefined reference
    

    linked lib:

    LIBS += $$PWD/interface/lib/tx1/libparam_msg.a  \
                 $$PWD/interface/lib/tx1/libengine.a  \
                 $$PWD/interface/open_lib/json-c-0.12.1/tx1/lib/libjson-c.a
    

    nm:

    nm libengine.a | grep od_msg_create_fix_trans:
    0000000000000000 T od_msg_create_fix_trans
    

    Regards

    K K 2 Replies Last reply 1 Aug 2017, 06:57
    0
    • A Alex_wang
      1 Aug 2017, 03:43

      Qt5 linked the static libraries which have defined by this function,but the error still appear:

      qt_odin.o:‘QOdinMsg::MsgQCreate()’ :
      qt_odin.cpp.text+0x14):function ‘od_msg_create_fix_trans(char const*, unsigned int, unsigned int, unsigned int) ’  undefined reference
      

      linked lib:

      LIBS += $$PWD/interface/lib/tx1/libparam_msg.a  \
                   $$PWD/interface/lib/tx1/libengine.a  \
                   $$PWD/interface/open_lib/json-c-0.12.1/tx1/lib/libjson-c.a
      

      nm:

      nm libengine.a | grep od_msg_create_fix_trans:
      0000000000000000 T od_msg_create_fix_trans
      

      Regards

      K Offline
      K Offline
      koahnig
      wrote on 1 Aug 2017, 06:57 last edited by
      #2

      @Alex_wang

      Did you check the signatures of paramters?

      What is the tool chain you are using?

      Vote the answer(s) that helped you to solve your issue(s)

      A 1 Reply Last reply 1 Aug 2017, 09:42
      0
      • A Offline
        A Offline
        Alex_wang
        wrote on 1 Aug 2017, 09:35 last edited by Alex_wang 8 Jan 2017, 09:41
        #3

        the compiler cmd :

        /home/suma/tx1/gcc/gcc-linaro-6.2.1-2016.11-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-g++ 
        -Wl,-rpath-link,/home/suma/tx1/Linux_for_Tegra/rootfs/usr/lib/aarch64-linux-gnu 
        -Wl,-rpath-link,/home/suma/tx1/Linux_for_Tegra/rootfs/usr/lib/aarch64-linux-gnu/tegra 
        -Wl,-rpath-link,/home/suma/tx1/Linux_for_Tegra/rootfs/usr/lib 
        -Wl,-rpath-link,/home/suma/tx1/Linux_for_Tegra/rootfs/lib/aarch64-linux-gnu 
        --sysroot=/home/suma/tx1/Linux_for_Tegra/rootfs
         -Wl,-O1 -Wl,-rpath,/usr/local/qt5/lib 
        -o GUIControlSystem 
        main.o ... ...  qt_odin.o qrc_qml.o ... ... moc_qt_odin.o   
        -L/home/suma/tx1/Linux_for_Tegra/rootfs/usr/lib/aarch64-linux-gnu 
        -L/home/suma/tx1/Linux_for_Tegra/rootfs/usr/lib 
        -L/home/suma/tx1/Linux_for_Tegra/rootfs/lib/aarch64-linux-gnu 
        /home/suma/interface/lib/tx1/libparam_msg.a 
        /home/suma/interface/lib/tx1/libengine.a 
        /home/suma/interface/open_lib/json-c-0.12.1/tx1/lib/libjson-c.a 
        -L/home/suma/tx1/qt/qt5/lib 
        -lQt5QuickWidgets -lQt5Quick -lQt5Widgets -lQt5Multimedia -lQt5Gui -lQt5Qml 
        -lQt5Network -lQt5Sql -lQt5SerialPort -lQt5Core -lGLESv2 
        -lpthread 
        
        1 Reply Last reply
        0
        • K koahnig
          1 Aug 2017, 06:57

          @Alex_wang

          Did you check the signatures of paramters?

          What is the tool chain you are using?

          A Offline
          A Offline
          Alex_wang
          wrote on 1 Aug 2017, 09:42 last edited by
          #4

          @koahnig
          hi,
          the tool chain is aarch64-linux-gnu-g++ (version 6.2.1)

          K 1 Reply Last reply 1 Aug 2017, 13:32
          0
          • A Alex_wang
            1 Aug 2017, 09:42

            @koahnig
            hi,
            the tool chain is aarch64-linux-gnu-g++ (version 6.2.1)

            K Offline
            K Offline
            koahnig
            wrote on 1 Aug 2017, 13:32 last edited by
            #5

            @Alex_wang

            For linux systems I am suggesting that you follow the rules for declaring libraries. or this here

            When I read your first post, I thought you are on windows because you are using windows notation for library declaration.

            AFAIK that would help in your case. For linux there has been always the split between library path (-L) and library (-l) in declaration. Not sure, if there are really any linux systems around being able to handle differently. Anyway it will not hurt following these rules. You can even do it on windows with MinGW tool chain.

            @Alex_wang said in Qt5 Compile with an error "undefined reference" when linking static libraries or dynamic libraries:

            main.o ... ... qt_odin.o qrc_qml.o ... ... moc_qt_odin.o
            -L/home/suma/tx1/Linux_for_Tegra/rootfs/usr/lib/aarch64-linux-gnu
            -L/home/suma/tx1/Linux_for_Tegra/rootfs/usr/lib
            -L/home/suma/tx1/Linux_for_Tegra/rootfs/lib/aarch64-linux-gnu
            /home/suma/interface/lib/tx1/libparam_msg.a <<<<<< those need a split
            /home/suma/interface/lib/tx1/libengine.a <<<<<< those need a split
            /home/suma/interface/open_lib/json-c-0.12.1/tx1/lib/libjson-c.a <<<<<< those need a split
            -L/home/suma/tx1/qt/qt5/lib
            -lQt5QuickWidgets -lQt5Quick -lQt5Widgets -lQt5Multimedia -lQt5Gui -lQt5Qml
            -lQt5Network -lQt5Sql -lQt5SerialPort -lQt5Core -lGLESv2
            -lpthread

            I have marked in the quoted section the three lines the linker cannot understand.

            @Alex_wang said in Qt5 Compile with an error "undefined reference" when linking static libraries or dynamic libraries:

            LIBS += -L$$PWD/interface/lib/tx1 -llibparam_msg.a  \
                         -L$$PWD/interface/lib/tx1 -llibengine.a  \
                         -L$$PWD/interface/open_lib/json-c-0.12.1/tx1 -llib/libjson-c.a
            

            This may work.
            I am not sure about the notation of libraries in linux. The naming seem to be too close to windows MinGW libs.

            Vote the answer(s) that helped you to solve your issue(s)

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mvuori
              wrote on 1 Aug 2017, 15:44 last edited by
              #6

              If that function is originally in a .c file, the traditional error is that in the header file (or in your manually pasted prototype) it has not been defined as extern "C".

              A 1 Reply Last reply 2 Aug 2017, 01:40
              1
              • A Alex_wang
                1 Aug 2017, 03:43

                Qt5 linked the static libraries which have defined by this function,but the error still appear:

                qt_odin.o:‘QOdinMsg::MsgQCreate()’ :
                qt_odin.cpp.text+0x14):function ‘od_msg_create_fix_trans(char const*, unsigned int, unsigned int, unsigned int) ’  undefined reference
                

                linked lib:

                LIBS += $$PWD/interface/lib/tx1/libparam_msg.a  \
                             $$PWD/interface/lib/tx1/libengine.a  \
                             $$PWD/interface/open_lib/json-c-0.12.1/tx1/lib/libjson-c.a
                

                nm:

                nm libengine.a | grep od_msg_create_fix_trans:
                0000000000000000 T od_msg_create_fix_trans
                

                Regards

                K Offline
                K Offline
                kshegunov
                Moderators
                wrote on 1 Aug 2017, 17:42 last edited by
                #7

                Read this very carefully.

                As @koahnig said you're not linking properly, also for static linking it's advisable (very, very advisable) you add the libraries to the PRE_TARGETDEPS variable in your project file, explanation here.

                Finally, if libengine.a has dependencies of its own on dynamic libraries, those have to be linked with the application/user code, which is my "educated" guess for why od_msg_create_fix_trans can't be found (the library list is on the short side). Where is this function defined?

                Read and abide by the Qt Code of Conduct

                A 1 Reply Last reply 2 Aug 2017, 01:38
                0
                • K kshegunov
                  1 Aug 2017, 17:42

                  Read this very carefully.

                  As @koahnig said you're not linking properly, also for static linking it's advisable (very, very advisable) you add the libraries to the PRE_TARGETDEPS variable in your project file, explanation here.

                  Finally, if libengine.a has dependencies of its own on dynamic libraries, those have to be linked with the application/user code, which is my "educated" guess for why od_msg_create_fix_trans can't be found (the library list is on the short side). Where is this function defined?

                  A Offline
                  A Offline
                  Alex_wang
                  wrote on 2 Aug 2017, 01:38 last edited by
                  #8

                  @kshegunov @koahnig

                  Hi,
                  .pro has been changed :

                  unix:!macx: LIBS += -L$$PWD/../../../../../opt/odin/lib/tx1/ -lparam_msg
                  INCLUDEPATH += $$PWD/../../../../../opt/odin/lib/tx1
                  DEPENDPATH += $$PWD/../../../../../opt/odin/lib/tx1
                  unix:!macx: PRE_TARGETDEPS += $$PWD/../../../../../opt/odin/lib/tx1/libparam_msg.a
                  
                  unix:!macx: LIBS += -L$$PWD/../../../../../opt/odin/lib/tx1/ -lengine
                  INCLUDEPATH += $$PWD/../../../../../opt/odin/lib/tx1
                  DEPENDPATH += $$PWD/../../../../../opt/odin/lib/tx1
                  unix:!macx: PRE_TARGETDEPS += $$PWD/../../../../../opt/odin/lib/tx1/libengine.a
                  
                  
                  unix:!macx: LIBS += -L$$PWD/../../../../../opt/odin/open_lib/json-c-0.12.1/tx1/lib/ -ljson-c
                  INCLUDEPATH += $$PWD/../../../../../opt/odin/open_lib/json-c-0.12.1/tx1/include
                  DEPENDPATH += $$PWD/../../../../../opt/odin/open_lib/json-c-0.12.1/tx1/include
                  unix:!macx: PRE_TARGETDEPS += $$PWD/../../../../../opt/odin/open_lib/json-c-0.12.1/tx1/lib/libjson-c.a
                  

                  But the error still ......

                  1 Reply Last reply
                  0
                  • M mvuori
                    1 Aug 2017, 15:44

                    If that function is originally in a .c file, the traditional error is that in the header file (or in your manually pasted prototype) it has not been defined as extern "C".

                    A Offline
                    A Offline
                    Alex_wang
                    wrote on 2 Aug 2017, 01:40 last edited by
                    #9

                    @mvuori
                    Hi,

                    I find that function is really in a .c file, and in the header file it is not be defined as extern "C".

                    I will try it.

                    1 Reply Last reply
                    0
                    • A Offline
                      A Offline
                      Alex_wang
                      wrote on 2 Aug 2017, 02:14 last edited by Alex_wang 8 Feb 2017, 02:15
                      #10

                      Hi,
                      @mvuori
                      @kshegunov @koahnig

                      Thank you for your reply

                      the error has been solved:
                      as mvuori said, the header file of the libs is not been defined extern "C"

                      1 Reply Last reply
                      0

                      10/10

                      2 Aug 2017, 02:14

                      • Login

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