Unsolved Can't link my library
-
@Sareban
Where exactly is yourtonelib
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? -
@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 . -
@JonB
#include <QMainWindow>
#include <tonegenlib.h>namespace Ui {
class MainWindow;
}class MainWindow : public QMainWindow
{
Q_OBJECTpublic:
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. -
Hi, can you show the tonegenlib.h file?
-
#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_OBJECTpublic:
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
-
Sorry, I was looking for where you #define TONEGENLIBSHARED_EXPORT, can you show the tonegenlib_global.h?
-
#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 :)
-
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?
-
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()
-
@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. -
@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 :))