【发布时间】:2012-12-17 15:37:56
【问题描述】:
过去 2 天我一直在寻找类似问题的答案并将其实施到我的代码中,但收效甚微。我有一个外部 .dll(Windows)的 API,并且我的 .cpp 文件中包含头文件以引用 API。
但是我有这个问题,无论我做什么,我总是得到一个未解析的外部符号,它在我的 .h 文件中引用了这一行。是的,我使用谷歌并修改了我在代码中找到的答案,但没有成功。
Foo.h
Class Foo {
public:
static Foo* Interface_Get(char* dllfilename);
Foo.cpp
// I declare this just underneath the #include "Foo.h" header
Foo *foo = 0;
在我的 main 函数中,我将它声明为 this(以及其他一些很好的函数)。
//This has already been created and both Header and .dll are in the same directory.
Foo::Interface_Get("bar.dll");
我得到了这个错误
error LNK2019: unresolved external symbol
"public: static class Foo * __cdecl Foo::Interface_Get(char *)"
我已经尝试了我所知道的一切(这是我第一次创建 .dll 的经验)我觉得我错过了一些非常明显的东西,但对于我的生活我看不到它。
整个 Foo.cpp
#include "Foo.h"
Foo* Foo::Interface_Get(char* dllfilename); //May not be redeclared outside class error
Foo* foo = 0;
bool Frame()
{
if (foo->Key_Down(DIK_ESCAPE))
return false;
return true;
}
INT WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, INT)
{
foo->Interface_Get("bar.dll");
foo->System_SetState(grSTATE_FRAME, Frame);
foo->System_SetState(grSTATE_WINDOWED, true);
foo->System_SetState(grSTATE_KEYBOARD, true);
foo->System_Initiate();
foo->System_Start();
foo->System_Shutdown();
foo->Inferface_Release();
return 0;
}
【问题讨论】:
-
您是否为
Interface_Get(char* dllfilename);提供了函数定义? -
Foo::Interface_Get是您的代码,还是在 DLL 中实现?如果它是你的,它是在你的程序中定义的吗?如果在 DLL 中,是否链接 DLL 并导出函数? -
Foo *foo = 0;这是干什么用的? -
为了完整起见添加它,因为它可以帮助某人。我有一个类似的问题,我知道我做了一些愚蠢的事情。原来我忘了在方法名称之前添加
ClassName:::(