PDA

View Full Version : Undefined reference in static binding in Linux



gcubar
3rd February 2011, 15:16
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?

high_flyer
3rd February 2011, 15:26
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?

gcubar
3rd February 2011, 15:53
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!

high_flyer
3rd February 2011, 16:23
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.

gcubar
3rd February 2011, 16:53
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:


class Q_CORE_EXPORT QProcess : public QIODevice
{
Q_OBJECT
public:

... all standard methods and variables

void setVerifyMutableProcess(bool verify);
bool getVerifyMutableProcess() const;

...
};



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!

high_flyer
3rd February 2011, 19:31
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?

gcubar
3rd February 2011, 19:57
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.


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.


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 += core gui
TEMPLATE = app
TARGET = livex
DESTDIR = ../../bin/exec/qt
CONFIG += staticlib debug release
DEFINES += QT_LARGEFILE_SUPPORT
QMAKE_LFLAGS_RELEASE += -static-libgcc
QMAKE_LFLAGS += -static-libgcc

DEPENDPATH += ../../forms \
../../sources \
../../resources \
../../includes

INCLUDEPATH += ../../includes \
.

win32 {
INCLUDEPATH += d:/libraries/boost_1_44_0
LIBPATH += c:/msys/mingw/lib
}

linux-g++ {
INCLUDEPATH += /usr/share/boost/boost_1_42_0
LIBPATH += /lib \
/usr/lib
}

LIBS += -lws2_32

CONFIG(debug, debug|release) {
OBJECTS_DIR += ../../bin/qt/debug
} else {
OBJECTS_DIR += ../../bin/qt/release
}

MOC_DIR += ../../bin/GeneratedFiles
UI_DIR += ../../bin/GeneratedFiles
RCC_DIR += ../../bin/GeneratedFiles

RESOURCES += ...
SOURCES += ...
HEADERS += ...
FORMS += ...

high_flyer
3rd February 2011, 20:11
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.

gcubar
4th February 2011, 18:35
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 .... ....


Judging from the error message, it looks like this is the original Qt lib.

Yes, I know.


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.


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.


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,


#QMAKE_LFLAGS_RELEASE += -static -static-libgcc
#QMAKE_LFLAGS += -static -static-libgcc

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


/usr/lib/libX11.a(CrGlCur.o): In function `open_library':
(.text+0x3b): warning: Using 'dlopen' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/local/Trolltech/Qt-4.6.2/lib/libQtCore.a(qfsfileengine_unix.o): In function `QFSFileEngine::owner(QAbstractFileEngine::FileOwn er) const':
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
/usr/lib/libglib-2.0.a(gutils.o): In function `g_get_any_init_do':
(.text+0x13f2): warning: Using 'getpwuid' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/libglib-2.0.a(gutils.o): In function `g_get_any_init_do':
(.text+0x13e5): warning: Using 'setpwent' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/libglib-2.0.a(gutils.o): In function `g_get_any_init_do':
(.text+0x13fa): warning: Using 'endpwent' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/libX11.a(GetDflt.o): In function `GetHomeDir':
(.text+0xa1): warning: Using 'getpwnam_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/local/Trolltech/Qt-4.6.2/lib/libQtGui.a(qapplication_x11.o): In function `sm_performSaveYourself(QSessionManagerPrivate*)':
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
/usr/lib/libICE.a(icetrans.o): In function `_IceTransSocketOpen':
(.text+0x154c): warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/libICE.a(icetrans.o): In function `_IceTransGetPeerNetworkId':
(.text+0x2656): warning: Using 'gethostbyaddr' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/libICE.a(icetrans.o): In function `_IceTransSocketUNIXConnect':
(.text+0x2849): warning: Using 'gethostbyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/libICE.a(icetrans.o): In function `_IceTransSocketINETConnect':
(.text+0x2eab): warning: Using 'getservbyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/libfontconfig.a(fcxml.o): In function `FcConfigMessage':
(.text+0xe4): undefined reference to `XML_GetCurrentLineNumber'
/usr/lib/libfontconfig.a(fcxml.o): In function `FcConfigMessage':
(.text+0x177): undefined reference to `XML_GetCurrentLineNumber'
/usr/lib/libfontconfig.a(fcxml.o): In function `FcConfigParseAndLoad':
(.text+0x116f): undefined reference to `XML_ParserCreate'
/usr/lib/libfontconfig.a(fcxml.o): In function `FcConfigParseAndLoad':
(.text+0x11b9): undefined reference to `XML_SetUserData'
/usr/lib/libfontconfig.a(fcxml.o): In function `FcConfigParseAndLoad':
(.text+0x11d1): undefined reference to `XML_SetDoctypeDeclHandler'
/usr/lib/libfontconfig.a(fcxml.o): In function `FcConfigParseAndLoad':
(.text+0x11e9): undefined reference to `XML_SetElementHandler'
/usr/lib/libfontconfig.a(fcxml.o): In function `FcConfigParseAndLoad':
(.text+0x11f9): undefined reference to `XML_SetCharacterDataHandler'
/usr/lib/libfontconfig.a(fcxml.o): In function `FcConfigParseAndLoad':
(.text+0x120c): undefined reference to `XML_GetBuffer'
/usr/lib/libfontconfig.a(fcxml.o): In function `FcConfigParseAndLoad':
(.text+0x124c): undefined reference to `XML_ParseBuffer'
/usr/lib/libfontconfig.a(fcxml.o): In function `FcConfigParseAndLoad':
(.text+0x1280): undefined reference to `XML_ParserFree'
/usr/lib/libfontconfig.a(fcxml.o): In function `FcConfigParseAndLoad':
(.text+0x1581): undefined reference to `XML_GetErrorCode'
/usr/lib/libfontconfig.a(fcxml.o): In function `FcConfigParseAndLoad':
(.text+0x1589): undefined reference to `XML_ErrorString'
/usr/lib/libX11.a(ClDisplay.o): In function `XCloseDisplay':
(.text+0xbe): undefined reference to `xcb_disconnect'
/usr/lib/libX11.a(OpenDis.o): In function `OutOfMemory':
(.text+0x40a): undefined reference to `xcb_disconnect'
/usr/lib/libX11.a(OpenDis.o): In function `XOpenDisplay':
(.text+0x7c1): undefined reference to `xcb_get_setup'
/usr/lib/libX11.a(OpenDis.o): In function `XOpenDisplay':
(.text+0xc2c): undefined reference to `xcb_get_maximum_request_length'
/usr/lib/libX11.a(xcb_lock.o): In function `_XPutXCBBuffer':
(.text+0xcd): undefined reference to `xcb_get_request_sent'
/usr/lib/libX11.a(xcb_lock.o): In function `_XPutXCBBuffer':
(.text+0x386): undefined reference to `xcb_get_request_sent'
/usr/lib/libX11.a(xcb_lock.o): In function `_XPutXCBBuffer':
(.text+0x3b5): undefined reference to `xcb_send_request'
/usr/lib/libX11.a(xcb_lock.o): In function `_XGetXCBBuffer':
(.text+0x5c8): undefined reference to `xcb_get_request_sent'
/usr/lib/libX11.a(xcb_lock.o): In function `_XGetXCBBuffer':
(.text+0x5db): undefined reference to `xcb_connection_has_error'
/usr/lib/libX11.a(xcb_lock.o): In function `_XCBUnlockDisplay':
(.text+0x70d): undefined reference to `xcb_xlib_unlock'
/usr/lib/libX11.a(xcb_lock.o): In function `_XCBUnlockDisplay':
(.text+0x744): undefined reference to `xcb_get_request_sent'
/usr/lib/libX11.a(xcb_lock.o): In function `_XCBLockDisplay':
(.text+0x7fd): undefined reference to `xcb_xlib_lock'
/usr/lib/libX11.a(xcb_disp.o): In function `_XConnectXCB':
(.text+0x9a): undefined reference to `xcb_parse_display'
/usr/lib/libX11.a(xcb_disp.o): In function `_XConnectXCB':
(.text+0x156): undefined reference to `xcb_connect_to_display_with_auth_info'
/usr/lib/libX11.a(xcb_disp.o): In function `_XConnectXCB':
(.text+0x174): undefined reference to `xcb_get_file_descriptor'
/usr/lib/libX11.a(xcb_disp.o): In function `_XConnectXCB':
(.text+0x19d): undefined reference to `xcb_generate_id'
/usr/lib/libX11.a(xcb_disp.o): In function `_XConnectXCB':
(.text+0x1a8): undefined reference to `xcb_connection_has_error'
/usr/lib/libX11.a(xcb_disp.o): In function `_XConnectXCB':
(.text+0x1dc): undefined reference to `xcb_connect'
/usr/lib/libX11.a(xcb_io.o): In function `wait_or_poll_for_event':
(.text+0x3ef): undefined reference to `xcb_wait_for_event'
/usr/lib/libX11.a(xcb_io.o): In function `wait_or_poll_for_event':
(.text+0x414): undefined reference to `xcb_poll_for_event'
/usr/lib/libX11.a(xcb_io.o): In function `process_responses':
(.text+0x4d6): undefined reference to `xcb_connection_has_error'
/usr/lib/libX11.a(xcb_io.o): In function `process_responses':
(.text+0x537): undefined reference to `xcb_xlib_unlock'
/usr/lib/libX11.a(xcb_io.o): In function `process_responses':
(.text+0x567): undefined reference to `xcb_xlib_lock'
/usr/lib/libX11.a(xcb_io.o): In function `process_responses':
(.text+0x601): undefined reference to `xcb_poll_for_reply'
/usr/lib/libX11.a(xcb_io.o): In function `_XReply':
(.text+0x904): undefined reference to `xcb_wait_for_reply'
/usr/lib/libX11.a(xcb_io.o): In function `_XReply':
(.text+0xa15): undefined reference to `xcb_xlib_unlock'
/usr/lib/libX11.a(xcb_io.o): In function `_XAllocIDs':
(.text+0xc75): undefined reference to `xcb_generate_id'
/usr/lib/libX11.a(xcb_io.o): In function `_XIDHandler':
(.text+0xcb8): undefined reference to `xcb_generate_id'
/usr/lib/libX11.a(xcb_io.o): In function `_XSend':
(.text+0xd65): undefined reference to `xcb_flush'
/usr/lib/libglib-2.0.a(gregex.o): In function `g_regex_get_string_number':
(.text+0x3af): undefined reference to `pcre_get_stringnumber'
/usr/lib/libglib-2.0.a(gregex.o): In function `g_regex_get_capture_count':
(.text+0x446): undefined reference to `pcre_fullinfo'
/usr/lib/libglib-2.0.a(gregex.o): In function `g_regex_get_max_backref':
(.text+0x476): undefined reference to `pcre_fullinfo'
... and others ...
make: *** [../../bin/exec/qt/livex] Error 1

Thanks.

gcubar
28th February 2011, 15:20
Well I solve the problem with Qt 4.7.1.

Thanks.