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. Ld: symbol(s) not found collect2: ld returned 1 exit status
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved General and Desktop
9 Posts 4 Posters 8.9k Views 1 Watching
  • 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.
  • L Offline
    L Offline
    luca72
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • G Offline
      G Offline
      giesbert
      wrote on last edited by
      #2

      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?

      Nokia Certified Qt Specialist.
      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

      1 Reply Last reply
      0
      • F Offline
        F Offline
        florent.revelut
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • L Offline
          L Offline
          luca72
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          • G Offline
            G Offline
            giesbert
            wrote on last edited by
            #5

            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.

            Nokia Certified Qt Specialist.
            Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

            1 Reply Last reply
            0
            • L Offline
              L Offline
              luca72
              wrote on last edited by
              #6

              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

              1 Reply Last reply
              0
              • F Offline
                F Offline
                florent.revelut
                wrote on last edited by
                #7

                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.

                1 Reply Last reply
                0
                • L Offline
                  L Offline
                  luca72
                  wrote on last edited by
                  #8

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

                  Luca

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    Shmuel6
                    wrote on last edited by
                    #9

                    [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!

                    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