[RESOLVED] Shared library - undefined symbol error



  • RESOLVED: Check 4th reply.

    Hello,

    I've developed a small shared library for handling local and tcp socket connections. Both of which have a class within the library for it self.

    I've first written the class for the tcp socket connections, and this one works just fine. Then I've created the class that handles local socket connections. When I try to use this class in my application I get the "undefined symbol error" when calling the constructor of the class handling local sockets.

    Here are the files of the shared library:
    qscbsocket_global.h
    @ #include <QtCore/QtGlobal>

    #if defined(QSCBSOCKET_LIBRARY)

    define QSCBSOCKET_EXPORT Q_DECL_EXPORT

    #else

    define QSCBSOCKET_EXPORT Q_DECL_IMPORT

    #endif@

    qscbsocket.h // This one works fine
    @#ifndef QSCBSOCKET_H
    #define QSCBSOCKET_H

    #include <QObject>
    #include <QTcpServer>
    #include <QTcpSocket>

    #include "qscbsocket_global.h"

    class QSCBSOCKET_EXPORT QScbSocket : public QObject
    {
    Q_OBJECT

    public:
    QScbSocket( QObject* parent = 0 );
    QScbSocket(QString,int,QObject *parent = 0);
    virtual ~QScbSocket();

    void setParameters(QString,int);
    void startLib();
    bool write(QString,int);
    QString readData(int,int maxSize = 0);
    void closeConnection(int);
    int makeConnection(QString,int);
    bool waitForConnection(int,int);

    private:
    void serverConnects();

    QTcpServer *p_tcpServer;
    QTcpSocket p_tcpSocket;
    QString m_hostName;
    int m_portNum;
    QMap<int,QTcpSocket
    > m_socketMap;

    private slots:
    void onReadyRead();
    void onDisconnected();
    void onNewConnection();

    signals:
    void newConnection(int,QString);
    void dataReady(int,QString);
    void disconnected(int);
    };

    #endif // QSCBSOCKET_H@

    qscblocalsocket.h // This is the troubling one
    @#ifndef QSCBLOCALSOCKET_H
    #define QSCBLOCALSOCKET_H

    #include <QObject>
    //#include <QLocalServer>
    //#include <QLocalSocket>

    #include "qscbsocket_global.h"

    class QSCBSOCKET_EXPORT QScbLocalSocket : public QObject
    {
    Q_OBJECT

    public:
    QScbLocalSocket( QObject* parent = 0 );
    virtual ~QScbLocalSocket() {};
    };

    #endif // QSCBLOCALSOCKET_H@

    As you can see there is nothing in this class except for the constructor and destructor. I had it all written but I commented out everything, to rule out any other method problems. But even like this it is not working.

    I've been googling and trying to resolve this issue a whole day yesterday, and couldn't get it working, so now I'm kinda desperate.

    Kind regards,
    Thomas


  • Moderators

    Welcome to devnet

    You should provide at least also the compile error message.



  • There is no compile error message.
    It's a runtime error. And sorry I forgot to include that.
    Error:
    ./qscbd: symbol lookup error: ./qscbd: undefined symbol: _ZN15QScbLocalSocketC1EP7QObject



  • Just a silly guess: Did you add the new class files (.h and .cpp) to your project file (.pro, HEADERS and SOURCES)?



  • I did indeed add them.
    @SOURCES += src/qscbsocket.cpp
    src/qscblocalsocket.cpp
    HEADERS += src/qscbsocket.h
    src/qscblocalsocket.h
    src/qscbsocket_global.h
    @
    I'm also linking to the library from my application:
    @INCLUDEPATH += ../qscbsocket/src
    LIBS = -L../qscbsocket -lqscbsocket
    TARGETDEPS = ../qscbsocket/libqscbsocket.so@

    Linker command linking application:
    @g++ -Wl,--no-undefined -Wl,-O1 -Wl,-rpath,/usr/lib64/qt/lib -o ../bin/qscbd build/release/.obj/unix/main.o build/release/.obj/unix/qscbserver.o build/release/.obj/unix/qscbsocketdata.o build/release/.obj/unix/qscbbackup.o build/release/.obj/unix/moc_qscbserver.o build/release/.obj/unix/moc_qscbsocketdata.o build/release/.obj/unix/moc_qscbbackup.o -L/usr/lib64/qt/lib -L../qscbsocket -lqscbsocket -lQtSql -L/usr/lib64/qt/lib -lQtNetwork -lQtCore -lpthread @

    Producing no errors.

    And this is the partial output of "nm -CD libqscbsocket.so.0.0.0:
    @0000000000003df0 T QScbLocalSocket::QScbLocalSocket(QObject*)
    0000000000003df0 T QScbLocalSocket::QScbLocalSocket(QObject*)@

    Class init is a simple:
    @QScbLocalSocket localSocket = new QScbLocalSocket();@

    Update:
    Argh...I feel a bit stupid now.
    After inspecting ldd output of my application, it is searching for the library installed in /usr/lib64/ and not in my development directories. And in /usr/lib64/ there was an earlier version of the lib installed, which did not contain definitions for QScbLocalSocket class.

    This has been resolved. Thank you anyway. :)

    Kind regards,
    Thomas



  • No problem, you're welcome. We all are hit by such errors from time to time, nothing to grieve about :)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.