How can I resolve quot;error LNK2019: unresolved external symbolquot;?(如何解决“错误 LNK2019:未解析的外部符号?)
问题描述
我正在开发这个 MFC 应用程序,它需要一个嵌入式数据库.因此,我开始为它寻找一个灵活、快速的可嵌入"数据库,并偶然发现了 SQLite.
I've got this MFC application I'm working on that needs to have an embedded database. So I went hunting for a slick, fast "embeddable" database for it and stumbled accross SQLite.
我用它创建了一个数据库,并用 Visual Studio 2008 创建了一个静态库项目.该库项目将用于另一个主项目.
I created a DB with it, and I created a static library project with Visual Studio 2008. the library project will be used in another main project.
在库项目中,我使用方法 AddFeedToDB(CFeed f)
创建了一个类 DBClass
.库项目使用来自 codeproject (cppsqlite3.lib
) 的 .lib
文件.
In the library project, I created a class DBClass
with a method AddFeedToDB(CFeed f)
. The library project uses the .lib
file from codeproject (cppsqlite3.lib
).
编译静态库时没有检测到错误,但是当我尝试在主项目中使用库项目文件时,我得到了这些类型的错误:
When compiling the static library, no error is detected, but when I try to use the library project file in the main project, I get these type of errors:
error LNK2019: unresolved external symbol "public:void __thiscall
CppSQLite3DB::close(void)" (?close@CppSQLite3DB@@QAEXXZ
referenced in function "public: int __thiscall
CTalkingFeedsDB::AddFeedToDB(class CFeed,char const*)" (?
AddFeedToDB@CTalkingFeedsDB@@QAEHVCFeed@@PDB@Z
我错过了什么?
推荐答案
不止一次发生在我身上,我认为符号 XXX
(即 ?close@CppSQLite3DB@@QAEXXZ
) 是 在导入库中,而实际的符号是 __impXXX
(即 __imp?close@CppSQLite3DB@@QAEXXZ
).
It happened to me more than once that I thought symbol XXX
(i.e. ?close@CppSQLite3DB@@QAEXXZ
) was in the import lib, while the actual symbol was __impXXX
(i.e. __imp?close@CppSQLite3DB@@QAEXXZ
).
然后在编译步骤中找到链接器错误的原因:编译器将生成要导入的 ?close@CppSQLite3DB@@QAEXXZ
符号,它应该 生成 __imp?close@CppSQLite3DB@@QAEXXZ
.这通常意味着函数声明本身没有 __declspec( dllimport )
.这可能是由于某些未定义的预处理器符号引起的.或者 __declspec
根本不存在...
The reason for the linker error is then to be found in the compilation step: the compiler will generate the ?close@CppSQLite3DB@@QAEXXZ
symbol to be imported, where it should generate __imp?close@CppSQLite3DB@@QAEXXZ
. This often means that the function declaration itself didn't have __declspec( dllimport )
. Which may be caused by some preprocessor symbol not being defined. Or the __declspec
not being there at all...
这篇关于如何解决“错误 LNK2019:未解析的外部符号"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何解决“错误 LNK2019:未解析的外部符号"?


基础教程推荐
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- 使用从字符串中提取的参数调用函数 2022-01-01
- Windows Media Foundation 录制音频 2021-01-01
- 从 std::cin 读取密码 2021-01-01
- 为什么语句不能出现在命名空间范围内? 2021-01-01
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01