Bonjour,

J'ai coder un chargeur de plugin qui fonctionne à merveille sous Windows et Mac mais pas sur Linux.

J'utilise Qt 4.6.2 sur toutes les architectures.
Linux: Debian 32Bits, GCC 4.3.2

Le "this->loader->instance()" fonctionne et le "dynamic_cast<Streamit::IPlugin *>" ne fonctionne pas et quand j'affiche le contenu de "QPluginLoader::errorString()" j'obtient un "Unknown error".

J'ai essayer de façon désespérée de mettre un "-rdynamic" dans le Makefile sous Linux sa n'a rien changé.

Merci d'avance de votre aide.

On part du principe que tous les headers nécessaires sont chargé pour le fonctionnement de ce code.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
 
bool                    Plugin::_loadLibrary()
{
    QStringList         nameFilters;
    Streamit::IPlugin   *instance;
 
    // List the possible extensions
    nameFilters << "*.dll" << "*.so" << "*.a" << "*.sl" << "*.dylib" << "*.bundle";
    QStringListIterator dir(QDir(this->path).entryList(nameFilters, QDir::Files));
    // Iterate over the files of the plugin directory
    while (dir.hasNext() && !this->loader)
    {
        // If the file name has the good extension
        if (QLibrary::isLibrary(dir.peekNext()))
        {
 
            this->loader = new QPluginLoader(this->path + dir.peekNext());
            this->libraryName = dir.peekNext();
            // If the plugin implements IPlugin
            if (!(instance = dynamic_cast<Streamit::IPlugin *>(this->loader->instance())))
            {
                std::cerr << "QPluginLoader::Error: " << this->loader->errorString() << std::endl;
                delete this->loader;
                this->loader = NULL;
            }
            delete instance;
        }
        dir.next();
    }
    if (!this->loader)
    {
        Log::error(tr("Unable to find the plugin library"), Properties("id", this->id).add("file", this->path + this->libraryName), "Plugin", "_load");
        return (false);
    }
    Log::trace(tr("Plugin library found"), Properties("id", this->id).add("file", this->path + this->libraryName), "Plugin", "_load");
    return (true);
}
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
 
#ifndef IPLUGIN_H
# define IPLUGIN_H
 
# include "IApi.h"
# include "IConfiguration.h"
 
namespace Streamit
{
    {
    public:
        virtual ~IPlugin() {}
 
        virtual bool    onLoad(Streamit::IApi *api) = 0;
        virtual void    onUnload() = 0;
        virtual bool    onInstall(Streamit::IApi *api) = 0;
        virtual void    onUninstall(Streamit::IApi *api) = 0;
    };
}
 
Q_DECLARE_INTERFACE (Streamit::IPlugin, "fr.streamit.IPlugin");
 
#endif // IPLUGIN_H