Results 1 to 10 of 10

Thread: Undefined reference in static binding in Linux

  1. #1
    Join Date
    May 2010
    Location
    Holguín City, Cuba
    Posts
    13
    Thanks
    1
    Qt products
    Qt3 Qt4 Qt/Embedded Qt Jambi
    Platforms
    Unix/X11 Windows

    Default Undefined reference in static binding in Linux

    Hi colleagues,
    I've been adding some functionalities to QProcess class of Qt that I need for my program, as a new methods and other features.

    When compiling Qt 4.6.2 on Linux Debian Lenny with static option everything worked fine, but when I call one of these new methods from my application and link using the -static options, It's returned the error:

    undefined reference ... <new methods added>

    If I compiled and linked without -static options Qt sources and my application on Linux, everything works fine, but I say more, if compiled and linked with -static options on Windows, It works well too.

    What could it be?

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Undefined reference in static binding in Linux

    I've been adding some functionalities to QProcess class of Qt that I need for my program, as a new methods and other features.
    To QProcess class it self, or a subclass?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    May 2010
    Location
    Holguín City, Cuba
    Posts
    13
    Thanks
    1
    Qt products
    Qt3 Qt4 Qt/Embedded Qt Jambi
    Platforms
    Unix/X11 Windows

    Default Re: Undefined reference in static binding in Linux

    Quote Originally Posted by high_flyer View Post
    To QProcess class it self, or a subclass?
    To QProcess class it self.

    I added some new methods and functionalities to this class in:

    qprocess.h
    qprocess_p.h
    qprocess_win.cpp
    qprocess_unix.cpp

    Then I update the similar include files in ../qt/include/Qt and ../qt/include/QtCore, that I don't know why this files are duplicated in this folders, things that don't occurs on Windows.

    Thanks for your quick reply!

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Undefined reference in static binding in Linux

    To QProcess class it self.
    Why??

    There is just no reason to do that!
    Who knows what you are breaking by doing that.

    Just subclass QProcess, and use your subclass!
    I am sure it will eliminate your linking problems as well.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  5. #5
    Join Date
    May 2010
    Location
    Holguín City, Cuba
    Posts
    13
    Thanks
    1
    Qt products
    Qt3 Qt4 Qt/Embedded Qt Jambi
    Platforms
    Unix/X11 Windows

    Default Re: Undefined reference in static binding in Linux

    Quote Originally Posted by high_flyer View Post
    Why??

    There is just no reason to do that!
    Who knows what you are breaking by doing that.
    I repeat all work fine on Windows, and in non-static release on Linux. The error coming with static release on Linux and only when gcc are binding libQtCore.a with my application.

    Imagine the new QProcess class like this:

    Qt Code:
    1. class Q_CORE_EXPORT QProcess : public QIODevice
    2. {
    3. Q_OBJECT
    4. public:
    5.  
    6. ... all standard methods and variables
    7.  
    8. void setVerifyMutableProcess(bool verify);
    9. bool getVerifyMutableProcess() const;
    10.  
    11. ...
    12. };
    To copy to clipboard, switch view to plain text mode 

    Quote Originally Posted by high_flyer View Post
    Just subclass QProcess, and use your subclass!
    I am sure it will eliminate your linking problems as well.
    Why?? It's long history.

    Well, try to be as brief as possible.

    There are some processes in both Windows and Linux, that run they create a new child that is not manipulated from the class QProcess and subsequently the parent is terminated. With this, we lose the links to the application itself because it ended the main thread/process and appeared new children(s) that are kept running. This type of processes/applications I called them "mutable". So, it was necessary to update the "pid" of the class and reconnect QProcess notifiers, pipers and others.

    I saw that this was not possible to do from a class inherited from QProcess , or maybe you can tell me more.

    Thanks again!

  6. #6
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Undefined reference in static binding in Linux

    The error coming with static release on Linux and only when gcc are binding libQtCore.a with my application.
    undefined reference ... <new methods added>
    It looks that for some reason you are not linking against the version that you changed.
    I can't tell why with out knowing much more details on your project settings, and even then it might be very tricky to find out.

    I saw that this was not possible to do from a class inherited from QProcess , or maybe you can tell me more.
    Why not?
    The only reason would be is if you need to change behavior of private methods and/or access private members.
    Do you?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  7. #7
    Join Date
    May 2010
    Location
    Holguín City, Cuba
    Posts
    13
    Thanks
    1
    Qt products
    Qt3 Qt4 Qt/Embedded Qt Jambi
    Platforms
    Unix/X11 Windows

    Default Re: Undefined reference in static binding in Linux

    Quote Originally Posted by high_flyer View Post
    It looks that for some reason you are not linking against the version that you changed.
    Yes, very possible, but I do not know how to determine which library itself (in libQtCore.a) is linked.

    Quote Originally Posted by high_flyer View Post
    I can't tell why with out knowing much more details on your project settings, and even then it might be very tricky to find out.
    Yes, I know; I understand that it is difficult to determine the cause of the problem.

    Quote Originally Posted by high_flyer View Post
    Why not?
    The only reason would be is if you need to change behavior of private methods and/or access private members.
    Do you?
    Yes, I modified the behaviour of some private methods, including QProcess_Private class methods.

    This is project file of my application:

    Qt Code:
    1. QT += core gui
    2. TEMPLATE = app
    3. TARGET = livex
    4. DESTDIR = ../../bin/exec/qt
    5. CONFIG += staticlib debug release
    6. DEFINES += QT_LARGEFILE_SUPPORT
    7. QMAKE_LFLAGS_RELEASE += -static-libgcc
    8. QMAKE_LFLAGS += -static-libgcc
    9.  
    10. DEPENDPATH += ../../forms \
    11. ../../sources \
    12. ../../resources \
    13. ../../includes
    14.  
    15. INCLUDEPATH += ../../includes \
    16. .
    17.  
    18. win32 {
    19. INCLUDEPATH += d:/libraries/boost_1_44_0
    20. LIBPATH += c:/msys/mingw/lib
    21. }
    22.  
    23. linux-g++ {
    24. INCLUDEPATH += /usr/share/boost/boost_1_42_0
    25. LIBPATH += /lib \
    26. /usr/lib
    27. }
    28.  
    29. LIBS += -lws2_32
    30.  
    31. CONFIG(debug, debug|release) {
    32. OBJECTS_DIR += ../../bin/qt/debug
    33. } else {
    34. OBJECTS_DIR += ../../bin/qt/release
    35. }
    36.  
    37. MOC_DIR += ../../bin/GeneratedFiles
    38. UI_DIR += ../../bin/GeneratedFiles
    39. RCC_DIR += ../../bin/GeneratedFiles
    40.  
    41. RESOURCES += ...
    42. SOURCES += ...
    43. HEADERS += ...
    44. FORMS += ...
    To copy to clipboard, switch view to plain text mode 

  8. #8
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Undefined reference in static binding in Linux

    Yes, very possible, but I do not know how to determine which library itself (in libQtCore.a) is linked.
    Well, libQtCore.a is should be the new lib you created, with your version of the QThread class.
    Did you build this lib, or is this the Qt original lib?
    Judging from the error message, it looks like this is the original Qt lib.
    The question is, why do have the original at all?
    You should download the Qt source (which clearly you have done) and compile Qt from source, where the source includes your changes.
    If you have no other Qt libs installed, you will have to link against the correct one.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  9. #9
    Join Date
    May 2010
    Location
    Holguín City, Cuba
    Posts
    13
    Thanks
    1
    Qt products
    Qt3 Qt4 Qt/Embedded Qt Jambi
    Platforms
    Unix/X11 Windows

    Default Re: Undefined reference in static binding in Linux

    Quote Originally Posted by high_flyer View Post
    Well, libQtCore.a is should be the new lib you created, with your version of the QThread class.
    Did you build this lib, or is this the Qt original lib?
    Yes, I rebuild this lib that was configured with Qt:

    ./configure -opensource -static .... ....

    Quote Originally Posted by high_flyer View Post
    Judging from the error message, it looks like this is the original Qt lib.
    Yes, I know.

    Quote Originally Posted by high_flyer View Post
    The question is, why do have the original at all?
    Original? I don't have the original. I know that libQtCore.a file is a new source code compiled, cuz it's has a new date and time.

    Quote Originally Posted by high_flyer View Post
    You should download the Qt source (which clearly you have done) and compile Qt from source, where the source includes your changes.
    I don't underdestand what you want to know about this. I download "qt-sdk-linux-x86-opensource" 4.6.2, then I installed, make a changes in the source code files, and then compiled.

    Quote Originally Posted by high_flyer View Post
    If you have no other Qt libs installed, you will have to link against the correct one.
    I think as well.

    I make some others changes in the project file of my application. I added '-static' options to this flags,

    Qt Code:
    1. #QMAKE_LFLAGS_RELEASE += -static -static-libgcc
    2. #QMAKE_LFLAGS += -static -static-libgcc
    To copy to clipboard, switch view to plain text mode 

    and the result of linking make new errors. The new errors are:

    Qt Code:
    1. /usr/lib/libX11.a(CrGlCur.o): In function `open_library':
    2. (.text+0x3b): warning: Using 'dlopen' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
    3. /usr/local/Trolltech/Qt-4.6.2/lib/libQtCore.a(qfsfileengine_unix.o): In function `QFSFileEngine::owner(QAbstractFileEngine::FileOwner) const':
    4. qfsfileengine_unix.cpp:(.text+0x9d9): warning: Using 'getgrgid_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
    5. /usr/lib/libglib-2.0.a(gutils.o): In function `g_get_any_init_do':
    6. (.text+0x13f2): warning: Using 'getpwuid' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
    7. /usr/lib/libglib-2.0.a(gutils.o): In function `g_get_any_init_do':
    8. (.text+0x13e5): warning: Using 'setpwent' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
    9. /usr/lib/libglib-2.0.a(gutils.o): In function `g_get_any_init_do':
    10. (.text+0x13fa): warning: Using 'endpwent' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
    11. /usr/lib/libX11.a(GetDflt.o): In function `GetHomeDir':
    12. (.text+0xa1): warning: Using 'getpwnam_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
    13. /usr/local/Trolltech/Qt-4.6.2/lib/libQtGui.a(qapplication_x11.o): In function `sm_performSaveYourself(QSessionManagerPrivate*)':
    14. qapplication_x11.cpp:(.text+0xb9d7): warning: Using 'getpwuid_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
    15. /usr/lib/libICE.a(icetrans.o): In function `_IceTransSocketOpen':
    16. (.text+0x154c): warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
    17. /usr/lib/libICE.a(icetrans.o): In function `_IceTransGetPeerNetworkId':
    18. (.text+0x2656): warning: Using 'gethostbyaddr' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
    19. /usr/lib/libICE.a(icetrans.o): In function `_IceTransSocketUNIXConnect':
    20. (.text+0x2849): warning: Using 'gethostbyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
    21. /usr/lib/libICE.a(icetrans.o): In function `_IceTransSocketINETConnect':
    22. (.text+0x2eab): warning: Using 'getservbyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
    23. /usr/lib/libfontconfig.a(fcxml.o): In function `FcConfigMessage':
    24. (.text+0xe4): undefined reference to `XML_GetCurrentLineNumber'
    25. /usr/lib/libfontconfig.a(fcxml.o): In function `FcConfigMessage':
    26. (.text+0x177): undefined reference to `XML_GetCurrentLineNumber'
    27. /usr/lib/libfontconfig.a(fcxml.o): In function `FcConfigParseAndLoad':
    28. (.text+0x116f): undefined reference to `XML_ParserCreate'
    29. /usr/lib/libfontconfig.a(fcxml.o): In function `FcConfigParseAndLoad':
    30. (.text+0x11b9): undefined reference to `XML_SetUserData'
    31. /usr/lib/libfontconfig.a(fcxml.o): In function `FcConfigParseAndLoad':
    32. (.text+0x11d1): undefined reference to `XML_SetDoctypeDeclHandler'
    33. /usr/lib/libfontconfig.a(fcxml.o): In function `FcConfigParseAndLoad':
    34. (.text+0x11e9): undefined reference to `XML_SetElementHandler'
    35. /usr/lib/libfontconfig.a(fcxml.o): In function `FcConfigParseAndLoad':
    36. (.text+0x11f9): undefined reference to `XML_SetCharacterDataHandler'
    37. /usr/lib/libfontconfig.a(fcxml.o): In function `FcConfigParseAndLoad':
    38. (.text+0x120c): undefined reference to `XML_GetBuffer'
    39. /usr/lib/libfontconfig.a(fcxml.o): In function `FcConfigParseAndLoad':
    40. (.text+0x124c): undefined reference to `XML_ParseBuffer'
    41. /usr/lib/libfontconfig.a(fcxml.o): In function `FcConfigParseAndLoad':
    42. (.text+0x1280): undefined reference to `XML_ParserFree'
    43. /usr/lib/libfontconfig.a(fcxml.o): In function `FcConfigParseAndLoad':
    44. (.text+0x1581): undefined reference to `XML_GetErrorCode'
    45. /usr/lib/libfontconfig.a(fcxml.o): In function `FcConfigParseAndLoad':
    46. (.text+0x1589): undefined reference to `XML_ErrorString'
    47. /usr/lib/libX11.a(ClDisplay.o): In function `XCloseDisplay':
    48. (.text+0xbe): undefined reference to `xcb_disconnect'
    49. /usr/lib/libX11.a(OpenDis.o): In function `OutOfMemory':
    50. (.text+0x40a): undefined reference to `xcb_disconnect'
    51. /usr/lib/libX11.a(OpenDis.o): In function `XOpenDisplay':
    52. (.text+0x7c1): undefined reference to `xcb_get_setup'
    53. /usr/lib/libX11.a(OpenDis.o): In function `XOpenDisplay':
    54. (.text+0xc2c): undefined reference to `xcb_get_maximum_request_length'
    55. /usr/lib/libX11.a(xcb_lock.o): In function `_XPutXCBBuffer':
    56. (.text+0xcd): undefined reference to `xcb_get_request_sent'
    57. /usr/lib/libX11.a(xcb_lock.o): In function `_XPutXCBBuffer':
    58. (.text+0x386): undefined reference to `xcb_get_request_sent'
    59. /usr/lib/libX11.a(xcb_lock.o): In function `_XPutXCBBuffer':
    60. (.text+0x3b5): undefined reference to `xcb_send_request'
    61. /usr/lib/libX11.a(xcb_lock.o): In function `_XGetXCBBuffer':
    62. (.text+0x5c8): undefined reference to `xcb_get_request_sent'
    63. /usr/lib/libX11.a(xcb_lock.o): In function `_XGetXCBBuffer':
    64. (.text+0x5db): undefined reference to `xcb_connection_has_error'
    65. /usr/lib/libX11.a(xcb_lock.o): In function `_XCBUnlockDisplay':
    66. (.text+0x70d): undefined reference to `xcb_xlib_unlock'
    67. /usr/lib/libX11.a(xcb_lock.o): In function `_XCBUnlockDisplay':
    68. (.text+0x744): undefined reference to `xcb_get_request_sent'
    69. /usr/lib/libX11.a(xcb_lock.o): In function `_XCBLockDisplay':
    70. (.text+0x7fd): undefined reference to `xcb_xlib_lock'
    71. /usr/lib/libX11.a(xcb_disp.o): In function `_XConnectXCB':
    72. (.text+0x9a): undefined reference to `xcb_parse_display'
    73. /usr/lib/libX11.a(xcb_disp.o): In function `_XConnectXCB':
    74. (.text+0x156): undefined reference to `xcb_connect_to_display_with_auth_info'
    75. /usr/lib/libX11.a(xcb_disp.o): In function `_XConnectXCB':
    76. (.text+0x174): undefined reference to `xcb_get_file_descriptor'
    77. /usr/lib/libX11.a(xcb_disp.o): In function `_XConnectXCB':
    78. (.text+0x19d): undefined reference to `xcb_generate_id'
    79. /usr/lib/libX11.a(xcb_disp.o): In function `_XConnectXCB':
    80. (.text+0x1a8): undefined reference to `xcb_connection_has_error'
    81. /usr/lib/libX11.a(xcb_disp.o): In function `_XConnectXCB':
    82. (.text+0x1dc): undefined reference to `xcb_connect'
    83. /usr/lib/libX11.a(xcb_io.o): In function `wait_or_poll_for_event':
    84. (.text+0x3ef): undefined reference to `xcb_wait_for_event'
    85. /usr/lib/libX11.a(xcb_io.o): In function `wait_or_poll_for_event':
    86. (.text+0x414): undefined reference to `xcb_poll_for_event'
    87. /usr/lib/libX11.a(xcb_io.o): In function `process_responses':
    88. (.text+0x4d6): undefined reference to `xcb_connection_has_error'
    89. /usr/lib/libX11.a(xcb_io.o): In function `process_responses':
    90. (.text+0x537): undefined reference to `xcb_xlib_unlock'
    91. /usr/lib/libX11.a(xcb_io.o): In function `process_responses':
    92. (.text+0x567): undefined reference to `xcb_xlib_lock'
    93. /usr/lib/libX11.a(xcb_io.o): In function `process_responses':
    94. (.text+0x601): undefined reference to `xcb_poll_for_reply'
    95. /usr/lib/libX11.a(xcb_io.o): In function `_XReply':
    96. (.text+0x904): undefined reference to `xcb_wait_for_reply'
    97. /usr/lib/libX11.a(xcb_io.o): In function `_XReply':
    98. (.text+0xa15): undefined reference to `xcb_xlib_unlock'
    99. /usr/lib/libX11.a(xcb_io.o): In function `_XAllocIDs':
    100. (.text+0xc75): undefined reference to `xcb_generate_id'
    101. /usr/lib/libX11.a(xcb_io.o): In function `_XIDHandler':
    102. (.text+0xcb8): undefined reference to `xcb_generate_id'
    103. /usr/lib/libX11.a(xcb_io.o): In function `_XSend':
    104. (.text+0xd65): undefined reference to `xcb_flush'
    105. /usr/lib/libglib-2.0.a(gregex.o): In function `g_regex_get_string_number':
    106. (.text+0x3af): undefined reference to `pcre_get_stringnumber'
    107. /usr/lib/libglib-2.0.a(gregex.o): In function `g_regex_get_capture_count':
    108. (.text+0x446): undefined reference to `pcre_fullinfo'
    109. /usr/lib/libglib-2.0.a(gregex.o): In function `g_regex_get_max_backref':
    110. (.text+0x476): undefined reference to `pcre_fullinfo'
    111. ... and others ...
    112. make: *** [../../bin/exec/qt/livex] Error 1
    To copy to clipboard, switch view to plain text mode 

    Thanks.

  10. #10
    Join Date
    May 2010
    Location
    Holguín City, Cuba
    Posts
    13
    Thanks
    1
    Qt products
    Qt3 Qt4 Qt/Embedded Qt Jambi
    Platforms
    Unix/X11 Windows

    Default Re: Undefined reference in static binding in Linux

    Well I solve the problem with Qt 4.7.1.

    Thanks.

Similar Threads

  1. Undefined reference
    By eekhoorn12 in forum Qt Programming
    Replies: 2
    Last Post: 6th January 2011, 15:45
  2. undefined reference
    By jayreddy in forum Qt Programming
    Replies: 1
    Last Post: 20th November 2009, 13:45
  3. Undefined reference to crt
    By derektaprell in forum Installation and Deployment
    Replies: 0
    Last Post: 20th October 2009, 08:34
  4. Undefined Reference To...
    By ManuMies in forum Qt Programming
    Replies: 6
    Last Post: 10th February 2009, 12:14
  5. Undefined reference
    By Salazaar in forum Newbie
    Replies: 12
    Last Post: 23rd May 2007, 10:21

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.