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
Forum Updated to NodeBB v4.3 + New Features

Can't link my library

Scheduled Pinned Locked Moved Unsolved Installation and Deployment
12 Posts 3 Posters 1.5k 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.
  • 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