How to connect sqlite to c++ program?

I can not connect to sqlite. Use the boilerplate code. Via the command line trying to compile it, but gets out error: File format not recognized. I have not seen the correct library connected to mingw. There are 2 packages. In one sqlite3.c and sqlite3.h. In another sqlite3.dll and sqlite3.def. How to connect? 5cfce9449dce3530654660.png
#include <stdio.h>
#include <sqlite3.h> 

int main(int argc, char* argv[]) {
 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));
return(0);
 } else {
 fprintf(stderr, "Opened database successfully\n");
}
sqlite3_close(db);
}
March 23rd 20 at 19:44
1 answer
March 23rd 20 at 19:46
Solution
You need to pass gcc is not a dll, and lib (import library). Generate it with the following command:
lib /def:sqlite3.def /out:sqlite3.lib /MACHINE:X64
The command should be run from Studio com. line. If you do not set, try dlltool:
dlltool -d sqlite3.def -l sqlite3.lib

Help dlltool: www.mingw.org/wiki/dlltool
DLL is also intended to connect to. - Mariela.OConn commented on March 23rd 20 at 19:49
Added lib file, which did dlltool in mingw folder/lib. Compiled without errors. Says the program can't start because of a missing (null).DLL - lauryn_Schmeler54 commented on March 23rd 20 at 19:52
What could be the reason? - lauryn_Schmeler54 commented on March 23rd 20 at 19:55
@lauryn_Schmeler54 sqlite3.dll next to the resulting exe-schnick put? This must be done manually. - Gaetano.Barro commented on March 23rd 20 at 19:58
@lauryn_Schmeler54 btw, in the message it says (null).DLL ? It's weird of course. - Gaetano.Barro commented on March 23rd 20 at 20:01
@Gaetano.Barro, Yes, it is written. sqlite3.dll lies in the same directory as the exe file. 5cfd03e30534c203011070.png - lauryn_Schmeler54 commented on March 23rd 20 at 20:04
@lauryn_Schmeler54 say what happens if the def file has no section of the LIBRARY. Add to the beginning of the def file LIBRARY "sqlite3.dll", pregenerate lib file and precompile project. - Gaetano.Barro commented on March 23rd 20 at 20:07
Yes, helped. Thank you very much. The program works - lauryn_Schmeler54 commented on March 23rd 20 at 20:10

Find more questions by tags SQLiteC++