C++ 从静态指针到函数的未定义引用
我正在尝试在运行时加载dll,我有一个问题:我有一个小助手类,它在主程序中声明。指向此对象的指针将传递给加载的dll。为了测试它,我想从类(printLine)调用一个函数。但我无法编译dll,因为我得到一个:C++ 从静态指针到函数的未定义引用,c++,eclipse,c++11,eclipse-cdt,C++,Eclipse,C++11,Eclipse Cdt,我正在尝试在运行时加载dll,我有一个问题:我有一个小助手类,它在主程序中声明。指向此对象的指针将传递给加载的dll。为了测试它,我想从类(printLine)调用一个函数。但我无法编译dll,因为我得到一个: Utility.o: In function `ZN7Utility6onInitEv': D:\Benutzer\Jan\Desktop\Programmierprojekte\Game Engine 5.0\Utilities\Debug/../Utility.cpp:7: unde
Utility.o: In function `ZN7Utility6onInitEv':
D:\Benutzer\Jan\Desktop\Programmierprojekte\Game Engine 5.0\Utilities\Debug/../Utility.cpp:7: undefined reference to `ModuleHelper::printLine(std::string)'
collect2.exe: error: ld returned 1 exit status
这两个文件是dll的唯一内容:
实用程序.h:
#ifndef UTILITY_H_
#define UTILITY_H_
#include <iostream>
#include <Definitions.h>
#include <ModuleHelper.h>
class Utility
{
public:
Utility();
~Utility();
static void onInit();
static void onUpdate();
static char* getName();
static char** getDependencies();
static int getCountDependencies();
static char* getServeAs();
static void setModuleHelper(ModuleHelper* helper);
private:
static constexpr char* name = "Utility";
static constexpr char** dependencies = nullptr;
static constexpr int countDependencies = 0;
static constexpr char* serveAs = "";
static ModuleHelper* moduleHelper;
};
extern "C" //GAME_API is a dllexport macro
{
char* GAME_API getName()
{
return Utility::getName();
}
char** GAME_API getDependencies()
{
return Utility::getDependencies();
}
int GAME_API getCountDependencies()
{
return Utility::getCountDependencies();
}
char* GAME_API getServeAs()
{
return Utility::getServeAs();
}
noargfunc GAME_API onInit()
{
return Utility::onInit;
}
noargfunc GAME_API onUpdate()
{
return Utility::onUpdate;
}
void GAME_API setModuleHelper(ModuleHelper* moduleHelper)
{
Utility::setModuleHelper(moduleHelper);
}
}
#endif /* UTILITY_H_ */
未定义的引用表示找不到实现 看起来您只是为了使用库才包含了头文件 主要问题(链接器错误-不是运行时!)是您可能忘记链接库。(Visual Studio中的项目参考) 无论如何,如果您可以编译并链接代码,您将发现下一个错误
ModuleHelper* Utility::moduleHelper; //with "= nullptr" or "= NULL" it didn't work either
如果您用NULL初始化moduleHelper,然后用“->”取消引用指针,尝试执行某项操作,您将得到NULL指针异常。
你必须初始化它。。。(可能是=新模块帮助)。因为我不知道使用过的库,你必须自己阅读文档 未定义的引用表示找不到实现 看起来您只是为了使用库才包含了头文件 主要问题(链接器错误-不是运行时!)是您可能忘记链接库。(Visual Studio中的项目参考) 无论如何,如果您可以编译并链接代码,您将发现下一个错误
ModuleHelper* Utility::moduleHelper; //with "= nullptr" or "= NULL" it didn't work either
如果您用NULL初始化moduleHelper,然后用“->”取消引用指针,尝试执行某项操作,您将得到NULL指针异常。
你必须初始化它。。。(可能是=新模块帮助)。因为我不知道使用过的库,你必须自己阅读文档 未定义的引用表示找不到实现 看起来您只是为了使用库才包含了头文件 主要问题(链接器错误-不是运行时!)是您可能忘记链接库。(Visual Studio中的项目参考) 无论如何,如果您可以编译并链接代码,您将发现下一个错误
ModuleHelper* Utility::moduleHelper; //with "= nullptr" or "= NULL" it didn't work either
如果您用NULL初始化moduleHelper,然后用“->”取消引用指针,尝试执行某项操作,您将得到NULL指针异常。
你必须初始化它。。。(可能是=新模块帮助)。因为我不知道使用过的库,你必须自己阅读文档 未定义的引用表示找不到实现 看起来您只是为了使用库才包含了头文件 主要问题(链接器错误-不是运行时!)是您可能忘记链接库。(Visual Studio中的项目参考) 无论如何,如果您可以编译并链接代码,您将发现下一个错误
ModuleHelper* Utility::moduleHelper; //with "= nullptr" or "= NULL" it didn't work either
如果您用NULL初始化moduleHelper,然后用“->”取消引用指针,尝试执行某项操作,您将得到NULL指针异常。
你必须初始化它。。。(可能是=新模块帮助)。因为我不知道使用过的库,你必须自己阅读文档 哦,谢谢,是的,我忘了连接cpp。但是你提到的另一件事应该不是问题,因为我在取消引用之前给setter打了电话。我使用的是一个自编的库。是的,我现在测试了它,我现在可以编译了,我没有得到nullpointer/Segfault噢,谢谢,是的,我忘了链接cpp。但是你提到的另一件事应该不是问题,因为我在取消引用之前给setter打了电话。我使用的是一个自编的库。是的,我现在测试了它,我现在可以编译了,我没有得到nullpointer/Segfault噢,谢谢,是的,我忘了链接cpp。但是你提到的另一件事应该不是问题,因为我在取消引用之前给setter打了电话。我使用的是一个自编的库。是的,我现在测试了它,我现在可以编译了,我没有得到nullpointer/Segfault噢,谢谢,是的,我忘了链接cpp。但是你提到的另一件事应该不是问题,因为我在取消引用之前给setter打了电话。我使用的是一个自编的库。是的,我现在测试了它,我现在可以编译了,但我没有得到nullpointer/segfault