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
The SQLite DLL file can be placed on Windows in C:WINDOWSsystem32 folder if needed to manage your database files.
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.
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.
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.
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 you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With