如何在我的 C++ 中包含 SQLite DLL项目?

发布于 2024-09-26 09:21:03 字数 1094 浏览 1 评论 0原文

我正在尝试通过 DLL 将 SQLite 添加到我的项目中。

我从下载页面下载了SQLiteDLL-3,提取了其内容(a DLL 和 .h 文件),并在其上运行 lib.exe 以生成 .lib 文件。然后,我在项目设置中的“链接器>>”下将包含 .lib 和 .dll 文件的目录设置为附加库目录。一般的。

然后我从下载页面下载了SQLiteSource-3,并将SQLite3.h文件解压到包含.Lib和.DLL文件的目录中,并将该目录添加为C/C++>>下的Additional Include Directory。一般的。我将 #include 添加到我的主文件中,然后在链接器>>中添加 sqlite3.dll 作为附加依赖项输入。

基本上我遵循了这个,但是当我运行它,我收到一条错误消息:

fatal error LNK1107: invalid or corrupt file: cannot read at 0x2B8

我尝试了多种方法来纠正它,包括在 x86 和 x64 下构建 .lib 文件,以及在其他依赖项列表中包含 .lib 文件的完整路径。我总是遇到这样的错误。似乎至少可以找到 .h 文件,因为如果我弄乱了包含中的名称,我会收到“找不到文件”错误,因此该部分似乎是正确的。

有人可以看到我可能做错了什么以及如何纠正这个问题吗?

更新: 通过将 .lib 文件(而不是 .dll 文件)添加到“其他依赖项”列表中,修复了“无效或损坏的文件”问题。现在我遇到了未解决的链接器错误:

错误LNK2019:函数_main中引用了无法解析的外部符号_sqlite3_exec

错误LNK2019:函数_main中引用了无法解析的外部符号_sqlite3_open

致命错误LNK1120:2个无法解析的外部

I'm trying to add SQLite to my project via a DLL.

I downloaded SQLiteDLL-3 from the download page, extracted its contents (a DLL and a .h file), and ran lib.exe on it to produce a .lib file. I then set the directory containing the .lib and the .dll files to be an Additional Library Directory, in the project settings, under Linker >> General.

Then I downloaded SQLiteSource-3 from the download page, and extracted the SQLite3.h file to the directory with the .Lib and .DLL files, and added that directory as an Additional Include Directory under C/C++ >> General. I added #include to my main file, and then added sqlite3.dll as an Additional Dependency in Linker >> Input.

Basically I followed this, but when I run it, I get an error saying:

fatal error LNK1107: invalid or corrupt file: cannot read at 0x2B8

I tried a number of things to correct it, including building the .lib file under both x86 and x64, and including the full path to the .lib file in the Additional Dependencies list. It's always that error that I get. It seems to at least be finding the .h file okay, because if I mess with the name in the include, I get a "cannot find the file" error, so that part appears to be correct.

Can someone see what I might be doing incorrectly and how to correct the issue?

Update:
Fixed the "invalid or corrupt file" issue by adding the .lib file to the Additional Dependies list, as opposed to the .dll file. Now I'm getting unresolved linker errors:

error LNK2019: unresolved external symbol _sqlite3_exec referenced in function _main

error LNK2019: unresolved external symbol _sqlite3_open referenced in function _main

fatal error LNK1120: 2 unresolved externals

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

各自安好 2024-10-03 09:21:03

以下是对我有用的方法:

在 Visual Studio 2010 中,单击“工具,VS 命令提示符”

在命令行窗口中,输入,例如:

lib /DEF:"C:\SQLite\sqlite3.def" /OUT:"C:\SQLite\sqlite3.lib"

在“解决方案资源管理器”窗口中,右键单击您的项目,添加“sqlite3.lib” “ 文件。

(您认为 SQLite 团伙可以在下载中包含 .lib 吗?)

Here's what worked for me:

In Visual Studio 2010, click on "Tools, VS Command Prompt"

In the command line window, enter, for example:

lib /DEF:"C:\SQLite\sqlite3.def" /OUT:"C:\SQLite\sqlite3.lib"

In the Solution Explorer window, right-click on your project, add the "sqlite3.lib" file.

(You'd think the SQLite gang could include a .lib in the download?)

菩提树下叶撕阳。 2024-10-03 09:21:03

如果我记得正确的话 sqlite 是用 C 编写的。
sqlite3.h 文件是否

extern "C" {}

包含声明?您可能遇到名称修改问题。

If I remember right sqlite is written in C.
Does the sqlite3.h file have

extern "C" {}

wrapping the declarations? You might be having name mangling issues.

鹤舞 2024-10-03 09:21:03

更新:SQLite 3.28 似乎没有附带 .DEF 文件。要创建 DEF 和 LIB,请执行以下操作:

:: Dump SQLite.DLL exports

set DUMPBIN="C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\Hostx86\x86\dumpbin.exe"
set LIBX="C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\Hostx86\x86\lib.exe"
set SQL="C:\SQLite\sqlite3.dll"
set DEF="C:\SQLite\sqlite3.def"
set LIB="C:\SQLite\sqlite3.lib"

:: [1] run dumpbin
%DUMPBIN% /EXPORTS /NOLOGO /OUT:%DEF% %SQL%

:: [2] manually edit .DEF file to look proper
:: [3] run LIB
%LIBX% /DEF:%DEF% /OUT:%LIB%

Update: SQLite 3.28 doesn't seem to ship with a .DEF file. To create the DEF and LIB, do:

:: Dump SQLite.DLL exports

set DUMPBIN="C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\Hostx86\x86\dumpbin.exe"
set LIBX="C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\Hostx86\x86\lib.exe"
set SQL="C:\SQLite\sqlite3.dll"
set DEF="C:\SQLite\sqlite3.def"
set LIB="C:\SQLite\sqlite3.lib"

:: [1] run dumpbin
%DUMPBIN% /EXPORTS /NOLOGO /OUT:%DEF% %SQL%

:: [2] manually edit .DEF file to look proper
:: [3] run LIB
%LIBX% /DEF:%DEF% /OUT:%LIB%
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文