1

我编写了一个 BitPacker 对象,该对象接收各种类型的数据,并使用存储其值所需的最少位数将它们打包到缓冲区中。我创建了一个单独的解决方案,将其制成一个 DLL 以实现重用能力。我成功地从另一个解决方案链接到它并使用它。但是,当我尝试为“数据”而不是 int 传递 long long 时,我遇到了 DLL 中这两个函数原型不明确的问题:

static __declspec(dllexport) unsigned long long UnpackBits(char *srcBuffer, long long data, unsigned int &offsetBits, const unsigned int numBits);
static __declspec(dllexport) unsigned int       UnpackBits(char *srcBuffer, int data, unsigned int &offsetBits, const unsigned int numBits);
static __declspec(dllexport) float              UnpackBits(char *srcBuffer, float data, unsigned int &offsetBits);

当我只是传递一个 int 时没有问题。由于我想不出一种方法来消除歧义以支持这两种数据类型,我决定通过注释掉头文件和源文件中的“long long”版本并重新编译它们(用于调试和发布)来修改 DLL 源. 但是,在这样做之后,我现在几乎每次调用该 DLL 都会收到链接器错误。我不知道为什么,因为我还将使用 long long 数据成员的实例更改为 int 以确保没有引用我注释掉的旧 long long 版本。

1>ChessGame.obj : error LNK2019: unresolved external symbol "public: static unsigned int __cdecl BitPacker::UnpackBits(char *,int,unsigned int &,unsigned int)" (?UnpackBits@BitPacker@@SAIPADHAAII@Z) referenced in function "public: class ChessGame * __thiscall ChessGame::LoadGame(char const *)" (?LoadGame@ChessGame@@QAEPAV1@PBD@Z)
1>Date.obj : error LNK2001: unresolved external symbol "public: static unsigned int __cdecl BitPacker::UnpackBits(char *,int,unsigned int &,unsigned int)" (?UnpackBits@BitPacker@@SAIPADHAAII@Z)
1>Turn.obj : error LNK2001: unresolved external symbol "public: static unsigned int __cdecl BitPacker::UnpackBits(char *,int,unsigned int &,unsigned int)" (?UnpackBits@BitPacker@@SAIPADHAAII@Z)
1>ChessGame.obj : error LNK2019: unresolved external symbol "public: static int __cdecl BitPacker::ReadFile(char const *,char *,int)" (?ReadFile@BitPacker@@SAHPBDPADH@Z) referenced in function "public: class ChessGame * __thiscall ChessGame::LoadGame(char const *)" (?LoadGame@ChessGame@@QAEPAV1@PBD@Z)
1>ChessGame.obj : error LNK2019: unresolved external symbol "public: static int __cdecl BitPacker::FileSize(char const *)" (?FileSize@BitPacker@@SAHPBD@Z) referenced in function "public: class ChessGame * __thiscall ChessGame::LoadGame(char const *)" (?LoadGame@ChessGame@@QAEPAV1@PBD@Z)
1>ChessGame.obj : error LNK2019: unresolved external symbol "public: static void __cdecl BitPacker::PackBits(char *,int,unsigned int &,unsigned int)" (?PackBits@BitPacker@@SAXPADHAAII@Z) referenced in function "public: int __thiscall ChessGame::SaveGame(char const *)" (?SaveGame@ChessGame@@QAEHPBD@Z)
1>Date.obj : error LNK2001: unresolved external symbol "public: static void __cdecl BitPacker::PackBits(char *,int,unsigned int &,unsigned int)" (?PackBits@BitPacker@@SAXPADHAAII@Z)
1>Turn.obj : error LNK2001: unresolved external symbol "public: static void __cdecl BitPacker::PackBits(char *,int,unsigned int &,unsigned int)" (?PackBits@BitPacker@@SAXPADHAAII@Z)
1>ChessGame.obj : error LNK2019: unresolved external symbol "public: static int __cdecl BitPacker::CopyBits(char *,char *,unsigned int &,unsigned int &,unsigned int)" (?CopyBits@BitPacker@@SAHPAD0AAI1I@Z) referenced in function "public: int __thiscall ChessGame::SaveGame(char const *)" (?SaveGame@ChessGame@@QAEHPBD@Z)
1>Turn.obj : error LNK2001: unresolved external symbol "public: static int __cdecl BitPacker::CopyBits(char *,char *,unsigned int &,unsigned int &,unsigned int)" (?CopyBits@BitPacker@@SAHPAD0AAI1I@Z)
1>ChessGameManager.obj : error LNK2019: unresolved external symbol "public: static bool __cdecl BitPacker::FileExists(char const *)" (?FileExists@BitPacker@@SA_NPBD@Z) referenced in function "public: void __thiscall ChessGameManager::RenderGameMenuIcons(void)" (?RenderGameMenuIcons@ChessGameManager@@QAEXXZ)
1>C:\Users\rvandyke\Documents\Visual Studio 2010\Projects\SuperChessW32_v003\Debug\SuperChessW32_v003.exe : fatal error LNK1120: 6 unresolved externals

我尝试清理调用项目,手动删除所有目标文件并执行 Rebuild All 但错误仍然存​​在。我认为它仍在使用旧版本的 DLL 头文件和/或 lib,但不知道如何或为什么。在我的调用解决方案中我需要做些什么来“重新识别”新的 DLL 吗?

PS - 当我问任何人对歧义问题有任何建议时?我希望能够同时支持 32 位和 64 位数据类型,但不确定如何。我想过简单地摆脱 int 版本,只使用 long long 版本,但后来我担心在将返回类型捕获回 int 时数据被截断的可能性。

4

0 回答 0