I have a simple hello world c++ program which links sqlite3.dll (64 bit version).
I have added sqlite3.h and sqlite3.dll correctly in the respective paths. The projects compiles for 64 bit architecture. The compilation and linking goes fine.
The problem arises when I try to run the exe.
I have seen many questions here that suggest to use dependency walker. I am putting the screenshot here:
I don't understands why it fails since the sqlite3.dll is in the exe's folder. And if I understand well dependency walker finds it. The arch column is x64 for all.
The source code:
#include <iostream>
#include "sqlite3.h"
int main()
{
std::cout<< "Hello world and all that" << std::endl;
sqlite3 *db;
char *zErrMsg = 0;
int rc;
rc = sqlite3_open("test.db", &db);
if( rc ){
fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
exit(0);
}else{
fprintf(stderr, "Opened database successfully\n");
}
sqlite3_close(db);
return 0;
}
I have also used the following utility if the exe and dll are both 64 bit: PE Deconstructor
. And both of them result to be 64 bit.
EDIT
I have compiled sqlite3.dll by myself following the instructions in
https://www.sqlite.org/howtocompile.html
with the following instructions:
1) loaded vcvars32.bat amd64
2) then I cd in:
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\amd64
3) and launch the command:
cl sqlite3.c -link -dll -out:sqlite3.dll /MACHINE:x64
EDIT 2
I tried the official sqlite3.dll + sqlite3.def (x64 binaries) converted to sqlite3.lib with the following command:
lib /def:sqlite3.def /OUT:sqlite3.lib /MACHINE:x64
with no luck, same error.
EDIT 3
I was putting the dll in the wrong folder (VS has a strange output dir tree with duplicated names). Now putting the official dll in the correct folder it works.
I managed to fix also my custom built dll, see accepted answer. I took the official sqlite3.def file and modified the compile command by adding the /def switch. Given the fact that the def was for a newer version of sqlite the linker complained for some missing symbols. I removed those symbols from the sqlite3.def file and it compiled correctly the dll file and also produced .lib and .exp files. (There is no need for the lib command now as the lib file is created directly). Putting the new dll in the correct folder works like a charm.
Please don't classify question as duplicate.
Thanks
Check if there is another sqlite3.dll in your path. When I tried it, I got the same error. It turns out there is a (32-bit?) sqlite3.dll in my python directory in the %PATH%. Copy the 64-bit dll to the same directory as your executable and run it again.
So as explained in comments, you need to download the DEF file from binary package: https://www.sqlite.org/2015/sqlite-dll-win64-x64-3090100.zip
Then you need to add this to
cl
compilation command:/DEF:sqlite3.def
Now your DLL will have required entries in export table.