问题描述
我有这个MFC应用程序,我工作,需要有一个嵌入式数据库。所以我去寻找一个漂亮,快速的可嵌入数据库,并且偶然碰到SQLite。
我创建了一个数据库,我创建了一个静态库项目
在库项目中,我创建了一个类 DBClass
使用方法 AddFeedToDB(CFeed f)
。库项目使用来自codeproject( cppsqlite3.lib
)的 .lib
文件。
当编译静态库时,没有检测到错误,但是当我尝试在主项目中使用库项目文件时,我得到这些类型的错误:
错误LNK2019:未解析的外部符号public:void __thiscall
CppSQLite3DB :: close(void)(?close @ CppSQLite3DB @@ QAEXXZ
引用in functionpublic:int __thiscall
CTalkingFeedsDB :: AddFeedToDB(class CFeed,char const *)(?
AddFeedToDB @ CTalkingFeedsDB @@ QAEHVCFeed @@ PDB @ Z
解决方案发生在我不止一次,我认为符号 XXX
(即?close @ CppSQLite3DB @@ QAEXXZ
) 在导入库中,而实际符号是 __ impXXX
(即 __ imp?close @ CppSQLite3DB @@ QAEXXZ
)。
然后在编译步骤中找到链接器错误的原因:编译器将生成?close @ CppSQLite3DB @@ QAEXXZ
符号,它应该 生成 __ imp?这通常意味着函数声明本身没有 __ declspec(dllimport)
。这可能是由一些预处理器符号未定义引起的。或 __ declspec
根本不存在...
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.
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.
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
What am I missing?
解决方案 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
).
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...
这篇关于如何解决“error LNK2019:unresolved external symbol”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!