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. [RESOLVED] Shared library - undefined symbol error
Forum Update on Monday, May 27th 2025

[RESOLVED] Shared library - undefined symbol error

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 12.4k 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.
  • X Offline
    X Offline
    xfirestorm
    wrote on last edited by
    #1

    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

    Those penguins....they sure ain't normal!

    1 Reply Last reply
    0
    • K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      Welcome to devnet

      You should provide at least also the compile error message.

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

      1 Reply Last reply
      0
      • X Offline
        X Offline
        xfirestorm
        wrote on last edited by
        #3

        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

        Those penguins....they sure ain't normal!

        1 Reply Last reply
        0
        • G Offline
          G Offline
          goetz
          wrote on last edited by
          #4

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

          http://www.catb.org/~esr/faqs/smart-questions.html

          1 Reply Last reply
          0
          • X Offline
            X Offline
            xfirestorm
            wrote on last edited by
            #5

            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

            Those penguins....they sure ain't normal!

            1 Reply Last reply
            0
            • G Offline
              G Offline
              goetz
              wrote on last edited by
              #6

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

              http://www.catb.org/~esr/faqs/smart-questions.html

              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