Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/130.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 无法引用其他插件中的方法_C++_Qt_Qt4 - Fatal编程技术网

C++ 无法引用其他插件中的方法

C++ 无法引用其他插件中的方法,c++,qt,qt4,C++,Qt,Qt4,我在PluginA中的classA中有一个方法,我能够在同一个插件中的所有类中编译和访问这个方法。 当我试图从另一个插件访问该方法时,我得到以下错误。虽然我能够从pluginB中引用和打印pluginA中的枚举 非常感谢您的指导 QT:4.8 IDE:QtCreator 4.4.0 操作系统:Windows 10 如果插件是独立的,则不能直接跨插件调用函数。 在这种情况下,如果确实需要跨插件调用函数,则需要使用GetProcAddress检索特定函数的地址。但是,这仅适用于使用extern C声

我在PluginA中的classA中有一个方法,我能够在同一个插件中的所有类中编译和访问这个方法。 当我试图从另一个插件访问该方法时,我得到以下错误。虽然我能够从pluginB中引用和打印pluginA中的枚举

非常感谢您的指导

QT:4.8 IDE:QtCreator 4.4.0 操作系统:Windows 10
如果插件是独立的,则不能直接跨插件调用函数。 在这种情况下,如果确实需要跨插件调用函数,则需要使用GetProcAddress检索特定函数的地址。但是,这仅适用于使用extern C声明的自由函数:

请注意,您可能希望使用EnumProcessModulesEx搜索所有可能加载的模块

如果pluginB在编译时链接到pluginA,这意味着您的pluginB的.pro文件中应该有LIBS+=-lpluginA。 还要确保在classA声明中使用了uu declspec dllexport和u declspec dllimport

如果您使用Qt Creator向导生成pluginA项目,您的代码中应该已经有类似的内容:

#ifdef _MSC_VER

    #if defined(LIBRARY_A)
        #define LIBRARY_A_EXPORT __declspec(dllexport)
    #else
        #define LIBRARY_A_EXPORT __declspec(dllimport)
    #endif

#else

    #define LIBRARY_A_EXPORT

#endif

只需确保classA定义如下所示:类库\导出classA

你的意思是你可以从pluginB打印PluginA的枚举吗?是的。对不起,打错了。编辑相同
// Somewher in pluginA
extern "C" void functionA() {}

// Somewhere in pluginB
using MyFunc = void(void);
MyFunc *pointer = GetProcAddress(module,TEXT("functionA"));
if (pointer)
    pointer(); // call "functionA()";
else
    qWarning("functionA() not found, pluginA not loaded");
#ifdef _MSC_VER

    #if defined(LIBRARY_A)
        #define LIBRARY_A_EXPORT __declspec(dllexport)
    #else
        #define LIBRARY_A_EXPORT __declspec(dllimport)
    #endif

#else

    #define LIBRARY_A_EXPORT

#endif