Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 "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

like image 221
Mike Pateras Avatar asked Oct 08 '10 19:10

Mike Pateras


People also ask

Where do I put the SQLite DLL?

The SQLite DLL file can be placed on Windows in C:WINDOWSsystem32 folder if needed to manage your database files.

How do I add a DLL to an existing project?

To create a DLL project in Visual Studio 2019On the menu bar, choose File > New > Project to open the Create a New Project dialog box. At the top of the dialog, set Language to C++, set Platform to Windows, and set Project type to Library.

How do I open sqlite3 DLL?

Install SQLite on Windows zip zipped files. Step 3 − Create a folder C:\>sqlite and unzip above two zipped files in this folder, which will give you sqlite3. def, sqlite3. dll and sqlite3.exe files.

How do I import a DLL into CPP?

Using a DLL in C++ code using LoadLibraryA function Now you need to first load the library using the LoadLibrary function which is defined in libloaderapi. h header and aliased to LoadLibraryW using #define macros. It accepts only one argument: a long pointer to wide string as the file name of the library.


1 Answers

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

like image 162
Pierre Avatar answered Oct 16 '22 17:10

Pierre