Ich habe jetzt nochmal seeehr viel rumprobiert und bin zu keinerlei Ergebnis gekommen, beim Erstellen von Shared Libs für mein QT Programm.
Nach etlichen Foreneinträgen habe ich mir mitlerweile die 3. Pro-Datei für die DLL gebaut und es funktioniert immernoch nicht. In der QT Doku zu Shared Libs steht; man bräuchte eine [Projektname]_global.h ?!
Kann mal jemand an dem folgenden Projekt zeigen was ihm auffällt, warum das Projekt nicht funktioniert?
PS: Es ist mir egal ob statisches oder dynamisches Linken, der Unterschied wird mir auch durch die Wiki-Artikel nicht deutlich. -.-
Die Ausgabe ist stehts: "Die Funktion hallo_dll konnte nicht geladen werden!
Cannot resolve "hallo_dll" in lool: Die angegebene Prozedur wurde nicht gefunden!"
*.pro-File der DLL (testDll.pro)
Code: Alles auswählen
-------------1.Versuch-------------
TARGET = lool
TEMPLATE = lib
HEADERS += lool.h
SOURCES += lool.cpp
-------------2.Versuch-------------
TARGET = lool
TEMPLATE = lib
HEADERS += lool.h\
lool_global.h
SOURCES += lool.cpp
DEFINES += LOOL_LIBRARY
-------------3.Versuch-------------
TARGET = lool
TEMPLATE = lib
HEADERS += lool.h\
lool_global.h
SOURCES += lool.cpp
DEFINES += LOOL_LIBRARY
CONFIG += staticlib
*.h-File der DLL (lool.h)
Code: Alles auswählen
-------------1.Versuch-------------
#ifndef LOOL_H
#define LOOL_H
#include <QtCore/qglobal.h>
#if defined(LOOL_LIBRARY)
# define LOOLSHARED_EXPORT Q_DECL_EXPORT
#else
# define LOOLSHARED_EXPORT Q_DECL_IMPORT
#endif
void Q_DECL_EXPORT hallo_dll();
#endif // LOOL_H
-------2.Versuch-------------
#ifndef LOOL_H
#define LOOL_H
#include <QtCore/qglobal.h>
#ifndef Q_DECL_EXPORT
# ifdef Q_OS_WIN
# define Q_DECL_EXPORT __declspec(dllexport)
# elif defined(QT_VISIBILITY_AVAILABLE)
# define Q_DECL_EXPORT __attribute__((visibility("default")))
# endif
# ifndef Q_DECL_EXPORT
# define Q_DECL_EXPORT
# endif
#endif
#ifndef Q_DECL_IMPORT
# ifdef Q_OS_WIN
# define Q_DECL_IMPORT __declspec(dllimport)
# else
# define Q_DECL_IMPORT
# endif
#endif
void Q_DECL_EXPORT hallo_dll();
#endif // LOOL_H
*.cpp-File der DLL (lool.cpp)
Code: Alles auswählen
#include "lool.h"
#include <QMessageBox>
void hallo_dll()
{
QMessageBox msgBox;
msgBox.setText("The document has been modified: Alone");
msgBox.exec();
}
*.pro-File meines Programms (myDllTest.pro)
Code: Alles auswählen
LIBS += "lool.dll"
HEADERS = mainwindow.h
SOURCES = mainwindow.cpp \
main.cpp
*.h-File meines Programms (mainwindow.h)
Code: Alles auswählen
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QWidget>
#include <QtGui>
class DLLFNC
{
private:
typedef void (*CBhallo_dll)();
public:
DLLFNC();
CBhallo_dll myhallo_dll;
};
class MainWindow : public QWidget{
Q_OBJECT
public:
MainWindow(QWidget *parent = 0);
DLLFNC *myDLLFNC;
};
#endif
*.cpp-File meines Programms (mainwindow.cpp)
Code: Alles auswählen
#include "mainwindow.h"
DLLFNC::DLLFNC()
{
QMessageBox msgBox;
QFile file("lool.dll");
if(file.exists()==true){
QLibrary myLib("lool");
if(myLib.isLibrary("lool.dll")==true){
if(myLib.load()==true){
if(myLib.isLoaded()==true){
myhallo_dll = (CBhallo_dll) myLib.resolve("hallo_dll");
if (myhallo_dll){
msgBox.setText("Die Funktion hallo_dll wurde erfolgreich geladen!\n");
msgBox.exec();
}else{
msgBox.setText("Die Funktion hallo_dll konnte nicht geladen werden!\n"+myLib.errorString());
msgBox.exec();
}
}else{
msgBox.setText("Die DLL lool wurde nicht geladen!\n"+myLib.errorString());
msgBox.exec();
}
}else{
msgBox.setText("Die DLL lool konnte nicht geladen werden!\n"+myLib.errorString());
msgBox.exec();
}
}else{
msgBox.setText("Die DLL lool ist keine Bibliothek\n"+myLib.errorString());
msgBox.exec();
}
}else{
msgBox.setText("Die DLL lool .dll existiert nicht an dem angegebenen Ort!");
msgBox.exec();
}
}
MainWindow::MainWindow(QWidget *parent)
: QWidget(parent)
{
myDLLFNC= new DLLFNC();
myDLLFNC->hallo_dll();
}
*.cpp-File des Programms (main.cpp)
Code: Alles auswählen
#include "mainwindow.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
MainWindow window;
window.show();
return app.exec();
}