views:

70

answers:

1

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

+1  A: 

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.

Jay
It does indeed. Any suggestions as to a solution?
Mike Pateras
When you run the program the dll file has to be in the same directory as the executable, or in the windows directory. (The lib file does not)
Jay
On your compile issues: I think you're using netbeans as an IDE? You've put in the directory where the lib file can be found but haven't told the project to include that specific library. Under Linker >> General >> Libraries >> Add Library File then choose the sqlite3.lib file.
Jay
I'm using Visual Studio. I ended up just shelling out to another app to do the inserts.
Mike Pateras