Ld: symbol(s) not found collect2: ld returned 1 exit status



  • Hello it this case i have this error:

    @
    #ifndef CLASSE_SCARICO_H
    #define CLASSE_SCARICO_H

    #include "Classe_scarico_global.h"
    #include <QTcpSocket>
    #include <fstream>
    #include <QHostAddress>
    #include <QProgressDialog>

    class CLASSE_SCARICOSHARED_EXPORT Classe_scarico : public QObject {
    Q_OBJECT
    public:
    Classe_scarico();
    ~Classe_scarico();

    private:
    QTcpSocket socket_scarico;
    int lung_file_scar, lung_scaricata;
    std::ofstream file_scarico;
    QProgressDialog pd;

    public slots:
    void connetto(QHostAddress indirizzo, QString porta, QString nome);

    private slots:
    void leggo_scarico(QString nome, QProgressDialog pd);
    void vedo();
    void socket_errore();
    };

    #endif // CLASSE_SCARICO_H
    @

    If i delete Q_OBJECT i never get the error why?

    EDIT: Please wrap code by Q-tags, Gerolf



  • Hi Luca,

    first of all, which tool chain do you use? I suggest mingw if it is windows?

    which OS?

    a bit more info of the error would be good: which symbols?

    do you compile the shared lib or the exe using the shared lib?

    how is CLASSE_SCARICOSHARED_EXPORT defined?



  • You might want to make sure that you actually reran qmake
    => your class derivates from QObject and it has slots/signals, to work, it actually needs to be moc'd up

    => check that you have MOC ran on your file (it should generate a moc_classe_scarico.cpp somewhere)

    Note that qmake knows which objects needs to be moc'd by analyzing for presence of the Q_OBJECT macro : if you added it after generating your project / makefile, it can't know it has to be moc'd up



  • Hello and thanks for your reply:
    the os is osx 10.6.6
    i use qtcreator now the class seems to be ok and the .h file is this:

    @
    class Classe_scarico : public QObject {
    Q_OBJECT

    public:
    Classe_scarico();
    ~Classe_scarico();

    private:
    QTcpSocket socket_scarico;
    int lung_file_scar, lung_scaricata;
    std::ofstream file_scarico;
    QProgressDialog pd;
    void leggo_scarico(QString nome, QProgressDialog pd);

    public slots:
    void connetto(QHostAddress indirizzo, QString porta, QString nome);

    private slots:
    void vedo();
    void socket_errore();
    };
    @

    But when i try to use it i get another error The .h of the other class is this:

    @
    namespace Ui {
    class Widget;
    }

    class Widget : public QWidget
    {
    Q_OBJECT

    public:
    explicit Widget(QWidget *parent = 0);
    ~Widget();

    private:
    Ui::Widget *ui;
    Classe_scarico *prova_scar;
    @

    but when in the cpp file i add this line in one function:

    @
    Widget::leggo_base() {
    prova_scar = new Classe_scarico;
    }
    @

    i get:
    Undefined symbols:
    "Classe_scarico::Classe_scarico()", referenced from:
    Widget::leggo_base() in widget.o
    ld: symbol(s) not found
    collect2: ld returned 1 exit status
    make: *** [Alex_rev_01.app/Contents/MacOS/Alex_rev_01] Error 1

    EDIT: please use @-tags for code highlighting, Gerolf



  • sounds like you have no cpp file with the implementation of Classe_scarico::Classe_scarico. Or the class is in a seperate dll and not exported. Or you don't link against the dll.



  • how i have to link?
    this is the are the .pro file of the two class:
    Classe_scarico.pro:
    QT += network
    TARGET = Classe_scarico
    TEMPLATE = lib
    DEFINES += CLASSE_SCARICO_LIBRARY
    SOURCES += classe_scarico.cpp
    HEADERS += classe_scarico.h
    Classe_scarico_global.h
    Alex_rev_1.pro:
    QT += core gui network webkit

    TARGET = Alex_rev_01
    TEMPLATE = app
    SOURCES += main.cpp
    widget.cpp
    HEADERS += widget.h
    FORMS += widget.ui
    INCLUDEPATH = /Users/lucabertolotti/Desktop/Qt/Progetti_C++/Classe_scarico/Classe_scarico
    Thanks

    Luca



  • Currently, you're telling Qt to build

    • an application on one side
    • a library on another side

    But you're not telling it that the application depends on your library
    in your Alex_rev_1.pro, add some information for the linker:
    @
    #name of your other library
    LIBS += -lClasse_scarico

    folder where it's generated

    LIBS += -L/Users/lucabertolotti/Desktop/Qt/Progetti_C++/Classe_scarico/Classe_scarico
    

    @

    Note that usually you don't have one class per library.



  • Many thanks
    Now it works, i'm beginner thanks for your time

    Luca



  • [quote author="florent.revelut" date="1300986306"]Currently, you're telling Qt to build

    • an application on one side
    • a library on another side

    But you're not telling it that the application depends on your library
    in your Alex_rev_1.pro, add some information for the linker:
    @
    #name of your other library
    LIBS += -lClasse_scarico

    folder where it's generated

    LIBS += -L/Users/lucabertolotti/Desktop/Qt/Progetti_C++/Classe_scarico/Classe_scarico
    

    @

    Note that usually you don't have one class per library.
    [/quote]

    Signed up just to say THANKS!!!
    I am running Knoppix 7.05 and was trying to install imapfilter but for the life of me could not understand why after installing all its dependences it still would not compile. Turns out OpenSSL was the culprit.
    Well thanks a TON.
    IOU1!


Log in to reply
 

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