Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    Unsolved Can't link my library

    Installation and Deployment
    3
    12
    750
    Loading More Posts
    • 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.
    • JonB
      JonB @Sareban last edited by

      @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 Reply Quote 0
      • S
        Sareban @JonB last edited by

        @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 Reply Quote 0
        • S
          Sareban @JonB last edited by

          @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 Reply Quote 0
          • hskoglund
            hskoglund last edited by

            Hi, can you show the tonegenlib.h file?

            S 1 Reply Last reply Reply Quote 0
            • S
              Sareban @hskoglund last edited by

              @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 Reply Quote 0
              • hskoglund
                hskoglund last edited by

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

                S 1 Reply Last reply Reply Quote 0
                • S
                  Sareban @hskoglund last edited by

                  @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 Reply Quote 0
                  • hskoglund
                    hskoglund last edited by 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 1 Reply Last reply Reply Quote 1
                    • S
                      Sareban @hskoglund last edited by 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()

                      hskoglund 1 Reply Last reply Reply Quote 0
                      • hskoglund
                        hskoglund @Sareban last edited by

                        @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 Reply Quote 2
                        • S
                          Sareban @hskoglund last edited by

                          @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 Reply Quote 0
                          • First post
                            Last post