I want to use sqlite3 as a database interface for my c++, so i decided to start from this tutorial: https://www.tutorialspoint.com/sqlite/sqlite_c_cpp.htm
I have installed sqlite3 on my computer and add a environment variable for it, but when I try to compile a very simple program as the tutorial suggest by typing
gcc test.c -l sqlite3
on command prompt, I get the following error:
test.c:2:10: fatal error: sqlite3.h: No such file or directory
2 | #include <sqlite3.h>
| ^~~~~~~~~~~
compilation terminated.
The test.c file is a folder on my desktop. The folder has the following structure:
test.c
shell.c
sqlite3.c
sqlite3.h
sqlite3ext.h
The last four files are from the amalgamation zip I found on the https://www.sqlite.org/download.html (sqlite-amalgamation-3320300.zip)
I have been looking on what is wrong for hours, and the only possible explanation i can find is that the compiler cant link the external sqlite3 library, but even then I could not find a linking method that works, any ideas on how I can compile the above?
test.c
#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);
}
I appreciate any help in advance.
Edit:
if I type #include "sqlite3.h" instead of #include <sqlite3.h> I get a different error:
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: cannot find -lsqlite3 collect2.exe: error: ld returned 1 exit status
.cAmalgamation file in your project. https://www.sqlite.org/amalgamation.html - drescherjmlibsqlite3.afile somewhere? Use-Lyour/path/hereto point the linker to the directory where you have it. - HolyBlackCatgcc test.c -l sqlite3You needgcc test.c sqlite3.c- drescherjm