开发者

How do I include a SQLite DLL in my C++ project?

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 "in开发者_运维技巧valid 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


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?)


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.


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%
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜