Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Installation and Deployment
  4. Can't link my library

Can't link my library

Scheduled Pinned Locked Moved Unsolved Installation and Deployment
12 Posts 3 Posters 1.7k 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.
  • S Offline
    S Offline
    Sareban
    wrote on last edited by Sareban
    #1

    I made a library in qt creator as c++ dynamic library option. But now i can' compile the project im using it.

    my .pro file is this;
    QT += core gui multimedia

    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

    TARGET = testlib2
    TEMPLATE = app

    DEFINES += QT_DEPRECATED_WARNINGS

    #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0

    CONFIG += c++11

    SOURCES +=
    main.cpp
    mainwindow.cpp

    HEADERS +=
    mainwindow.h

    FORMS +=
    mainwindow.ui

    Default rules for deployment.

    qnx: target.path = /tmp/$${TARGET}/bin
    else: unix:!android: target.path = /opt/$${TARGET}/bin
    !isEmpty(target.path): INSTALLS += target

    unix|win32: LIBS += -L$$PWD/../build-tonegenlib-Desktop_Qt_5_12_1_MinGW_64_bit-Debug/debug/ -ltonegenlib

    INCLUDEPATH += $$PWD/../tonegenlib
    DEPENDPATH += $$PWD/../tonegenlib

    and the compile errror is this ;

    debug/mainwindow.o: In function MainWindow::MainWindow(QWidget*)': C:\QT_workspace\build-testlib2-Desktop_Qt_5_12_1_MinGW_64_bit-Debug/../testlib2/mainwindow.cpp:6: undefined reference to __imp__ZN10TonegenlibC1Ev'
    collect2.exe: error: ld returned 1 exit status
    mingw32-make[1]: *** [Makefile.Debug:69: debug/testlib2.exe] Error 1
    mingw32-make: *** [Makefile:38: debug] Error 2
    mingw32-make[1]: Leaving directory 'C:/QT_workspace/build-testlib2-Desktop_Qt_5_12_1_MinGW_64_bit-Debug'
    01:29:22: The process "C:\Qt\Qt5.12.1\Tools\mingw730_64\bin\mingw32-make.exe" exited with code 2.
    Error while building/deploying project testlib2 (kit: Desktop Qt 5.12.1 MinGW 64-bit)
    When executing step "Make"
    01:29:22: Elapsed time: 00:01.

    thank you so much for your help.

    JonBJ 1 Reply Last reply
    0
    • S Sareban

      I made a library in qt creator as c++ dynamic library option. But now i can' compile the project im using it.

      my .pro file is this;
      QT += core gui multimedia

      greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

      TARGET = testlib2
      TEMPLATE = app

      DEFINES += QT_DEPRECATED_WARNINGS

      #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0

      CONFIG += c++11

      SOURCES +=
      main.cpp
      mainwindow.cpp

      HEADERS +=
      mainwindow.h

      FORMS +=
      mainwindow.ui

      Default rules for deployment.

      qnx: target.path = /tmp/$${TARGET}/bin
      else: unix:!android: target.path = /opt/$${TARGET}/bin
      !isEmpty(target.path): INSTALLS += target

      unix|win32: LIBS += -L$$PWD/../build-tonegenlib-Desktop_Qt_5_12_1_MinGW_64_bit-Debug/debug/ -ltonegenlib

      INCLUDEPATH += $$PWD/../tonegenlib
      DEPENDPATH += $$PWD/../tonegenlib

      and the compile errror is this ;

      debug/mainwindow.o: In function MainWindow::MainWindow(QWidget*)': C:\QT_workspace\build-testlib2-Desktop_Qt_5_12_1_MinGW_64_bit-Debug/../testlib2/mainwindow.cpp:6: undefined reference to __imp__ZN10TonegenlibC1Ev'
      collect2.exe: error: ld returned 1 exit status
      mingw32-make[1]: *** [Makefile.Debug:69: debug/testlib2.exe] Error 1
      mingw32-make: *** [Makefile:38: debug] Error 2
      mingw32-make[1]: Leaving directory 'C:/QT_workspace/build-testlib2-Desktop_Qt_5_12_1_MinGW_64_bit-Debug'
      01:29:22: The process "C:\Qt\Qt5.12.1\Tools\mingw730_64\bin\mingw32-make.exe" exited with code 2.
      Error while building/deploying project testlib2 (kit: Desktop Qt 5.12.1 MinGW 64-bit)
      When executing step "Make"
      01:29:22: Elapsed time: 00:01.

      thank you so much for your help.

      JonBJ Online
      JonBJ Online
      JonB
      wrote on last edited by
      #2

      @Sareban
      Where exactly is your tonelib file (full name & path) on the disk?
      Do you build it yourself?
      Are you sure it's MinGW and not, say, MSVC?
      Are you sure it's 64-bit and not 32-bit?
      Have you included the right header file for it, and are you calling a function in it which is correctly exported?

      S 2 Replies Last reply
      0
      • JonBJ JonB

        @Sareban
        Where exactly is your tonelib file (full name & path) on the disk?
        Do you build it yourself?
        Are you sure it's MinGW and not, say, MSVC?
        Are you sure it's 64-bit and not 32-bit?
        Have you included the right header file for it, and are you calling a function in it which is correctly exported?

        S Offline
        S Offline
        Sareban
        wrote on last edited by
        #3

        @JonB
        thanks for your reply. I supplied the full name and path to the .pro file with add library thing on qt. and i built it and qmake with the same kit and compiler i do with every other project. add library seeks for .a file and i provided it with that in the same folder of debug .dll .

        1 Reply Last reply
        0
        • JonBJ JonB

          @Sareban
          Where exactly is your tonelib file (full name & path) on the disk?
          Do you build it yourself?
          Are you sure it's MinGW and not, say, MSVC?
          Are you sure it's 64-bit and not 32-bit?
          Have you included the right header file for it, and are you calling a function in it which is correctly exported?

          S Offline
          S Offline
          Sareban
          wrote on last edited by
          #4

          @JonB
          #include <QMainWindow>
          #include <tonegenlib.h>

          namespace Ui {
          class MainWindow;
          }

          class MainWindow : public QMainWindow
          {
          Q_OBJECT

          public:
          explicit MainWindow(QWidget *parent = nullptr);
          ~MainWindow();

          Tonegenlib tonegen;
          
          
          
          void test();
          

          private:
          Ui::MainWindow *ui;
          };

          this is the header file of the project.

          void MainWindow::test()
          {
          tonegen.m_freq = 240;
          tonegen.playAudio();

          }

          and this is the .cpp where i call the function and change a variable.
          without using the library there is no errors but when i define tonegen and then call the function gives error.

          1 Reply Last reply
          0
          • hskoglundH Online
            hskoglundH Online
            hskoglund
            wrote on last edited by
            #5

            Hi, can you show the tonegenlib.h file?

            S 1 Reply Last reply
            0
            • hskoglundH hskoglund

              Hi, can you show the tonegenlib.h file?

              S Offline
              S Offline
              Sareban
              wrote on last edited by
              #6

              @hskoglund

              #ifndef TONEGENLIB_H
              #define TONEGENLIB_H

              #include "tonegenlib_global.h"
              #include <QBuffer>
              #include <QByteArray>
              #include <QMainWindow>
              #include <QAudio>
              #include <QtMultimedia/QAudioOutput>
              #include <QScopedPointer>
              #include <QFile>
              #include <QObject>
              #include <QFile>
              #include <QDataStream>
              #include <QIODevice>
              #include <QtMultimedia/QAudioDeviceInfo>
              #include <QtMultimedia/QAudioFormat>

              class TONEGENLIBSHARED_EXPORT Tonegenlib : public QWidget
              {
              Q_OBJECT

              public:
              Tonegenlib();
              void toneGenerate();
              void playAudio();
              void saveSound();
              void readFile();
              int SAMPLE_RATE = 44100;
              int m_seconds=2;
              int m_freq=50;
              int m_ph;
              int m_amp = 5;

              private:

              int len= m_seconds*SAMPLE_RATE;
              
              QAudioFormat format;
              QByteArray sinbuf;
              QBuffer sininput;
              QAudioOutput *audio;
              

              private slots:
              void handleStateChanged(QAudio::State newState);
              void supplyData();
              };

              #endif // TONEGENLIB_H

              this is my tonelib.h

              1 Reply Last reply
              0
              • hskoglundH Online
                hskoglundH Online
                hskoglund
                wrote on last edited by
                #7

                Sorry, I was looking for where you #define TONEGENLIBSHARED_EXPORT, can you show the tonegenlib_global.h?

                S 1 Reply Last reply
                0
                • hskoglundH hskoglund

                  Sorry, I was looking for where you #define TONEGENLIBSHARED_EXPORT, can you show the tonegenlib_global.h?

                  S Offline
                  S Offline
                  Sareban
                  wrote on last edited by
                  #8

                  @hskoglund

                  #ifndef TONEGENLIB_GLOBAL_H
                  #define TONEGENLIB_GLOBAL_H

                  #include <QtCore/qglobal.h>

                  #if defined(TONEGENLIB_LIBRARY)

                  define TONEGENLIBSHARED_EXPORT Q_DECL_EXPORT

                  #else

                  define TONEGENLIBSHARED_EXPORT Q_DECL_IMPORT

                  #endif

                  #endif // TONEGENLIB_GLOBAL_H

                  thanks for your help :)

                  1 Reply Last reply
                  0
                  • hskoglundH Online
                    hskoglundH Online
                    hskoglund
                    wrote on last edited by hskoglund
                    #9

                    Hmm, just a guess but it seems Tonegenlib's constructor isn't visible, can you show the code for Tonegenlib::Tonegenlib in your tonelib.cpp file?

                    S 1 Reply Last reply
                    1
                    • hskoglundH hskoglund

                      Hmm, just a guess but it seems Tonegenlib's constructor isn't visible, can you show the code for Tonegenlib::Tonegenlib in your tonelib.cpp file?

                      S Offline
                      S Offline
                      Sareban
                      wrote on last edited by Sareban
                      #10

                      @hskoglund

                      oh ok. do i need a constructor and deconstructor in a shared library cpp file ? didnt know that. i just started the code with the first function needed.

                      void Tonegenlib::toneGenerate() i started like this.

                      is there anything i need to consider when writing the constructor of the cpp ?

                      or is it enough to start with tonegenlib::tonegenlib()

                      hskoglundH 1 Reply Last reply
                      0
                      • S Sareban

                        @hskoglund

                        oh ok. do i need a constructor and deconstructor in a shared library cpp file ? didnt know that. i just started the code with the first function needed.

                        void Tonegenlib::toneGenerate() i started like this.

                        is there anything i need to consider when writing the constructor of the cpp ?

                        or is it enough to start with tonegenlib::tonegenlib()

                        hskoglundH Online
                        hskoglundH Online
                        hskoglund
                        wrote on last edited by
                        #11

                        @Sareban You don't need a constructor because it's a shared library, but since you mention the constructor in tonelib.h:

                        ...
                        public:
                        Tonegenlib();
                        ...
                        

                        either define an empty constructor in tonelib.cpp Tonegenlib::Tonegenlib() {} or remove the line from tonelib.h.

                        S 1 Reply Last reply
                        2
                        • hskoglundH hskoglund

                          @Sareban You don't need a constructor because it's a shared library, but since you mention the constructor in tonelib.h:

                          ...
                          public:
                          Tonegenlib();
                          ...
                          

                          either define an empty constructor in tonelib.cpp Tonegenlib::Tonegenlib() {} or remove the line from tonelib.h.

                          S Offline
                          S Offline
                          Sareban
                          wrote on last edited by
                          #12

                          @hskoglund
                          thank you so much :) first tried to define an empty constructor but it didnt work but then when i cleared the line from the .h it worked. thanks so much :))

                          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