QLibrary не может разрешить функцию в разделяемой библиотеке

Я пытаюсь включить функции динамически из общей библиотеки, созданной с помощью Qt. Я использую QLibrary, чтобы сделать это. Но у меня есть следующая проблема: когда я пытаюсь вызвать метод QLibrary :: resol (), он всегда возвращает 0.

Это заголовочный файл qtarithmetic.h моей общей библиотеки:

#ifndef QTARITHMETIC_H
#define QTARITHMETIC_H

#include <QtCore/qglobal.h>

#if defined(QTARITHMETIC_LIBRARY)
#  define QTARITHMETICSHARED_EXPORT Q_DECL_EXPORT
#else
#  define QTARITHMETICSHARED_EXPORT Q_DECL_IMPORT
#endif

class QTARITHMETICSHARED_EXPORT Qtarithmetic
{

public:
Qtarithmetic();
int add(int, int);
int sub(int, int);
};

#endif // QTARITHMETIC_H

Это файл cpp qtarithmetic.cpp моей общей библиотеки:

#include "qtarithmetic.h"
Qtarithmetic::Qtarithmetic() {}

extern "C" QTARITHMETICSHARED_EXPORT int Qtarithmetic::add(int a, int b) {
return a + b;
}

extern "C" QTARITHMETICSHARED_EXPORT int Qtarithmetic::sub(int a, int b) {
return a - b;
}

Это .профессионал файл тестового проекта, который использует мою библиотеку:

QT       += core

QT       -= gui

TARGET = qt-arithmetic-use
CONFIG   += console
CONFIG   -= app_bundle

TEMPLATE = app

SOURCES += main.cpp

Это .CPP файл этого тестового проекта:

#include <QCoreApplication>
#include <QProcess>
#include <QString>
#include <QTextStream>
#include <QDebug>
#include <QLibrary>

int main() {
QTextStream out(stdout);
int a = 0, b = 0, r1 = 0, r2 = 0;
a = 3; b = 4;

QLibrary library("/home/danil/build-qt-arithmetic-Desktop-Debug/libqt-arithmetic.so");
if (!library.load())
out << library.errorString() << endl;
if (library.load())
out << "library loaded" << endl;

typedef int (*MyPrototype)(int, int);

MyPrototype myFunction = (MyPrototype)library.resolve("add");
if (myFunction)
r1 = myFunction(a,b);
else
out << library.errorString() << endl;

MyPrototype myFunction2 = (MyPrototype)library.resolve("sub");
if (myFunction2)
r2 = myFunction2(a,b);
else
out << library.errorString() << endl;

out << r1 << " " << r2 << endl;

return 0;
}

library.errorString () содержит следующую информацию:

Cannot resolve symbol "add" in /home/danil/build-qt-arithmetic-Desktop-Debug/libqt-arithmetic.so: (/home/danil/build-qt-arithmetic-Desktop-Debug/libqt-arithmetic.so: undefined symbol: add)
Cannot resolve symbol "sub" in /home/danil/build-qt-arithmetic-Desktop-Debug/libqt-arithmetic.so: (/home/danil/build-qt-arithmetic-Desktop-Debug/libqt-arithmetic.so: undefined symbol: sub)

0

Решение

Задача ещё не решена.

Другие решения


По вопросам рекламы [email protected]