Reputation:
Though there are a few earlier posts on this issue, I still can't find any right solution - any help is appriciated.
I followed this instruction and took the below steps for installation:
sqlite3
command from my project folder "C:\proj" now works.
I then followed this instruction and to run the program:
Code (test.c) saved under "C:\proj" :
#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);
}
In addition, since above code uses #include <sqlite3.h>
, I downloaded sqlite-amalgamation-3240000.zip and extracted the "sqlite3.h" file to the same "C:\sqlite" location.
Command executed from "C:\proj":
gcc test.c -o test -I\sqlite -l sqlite3
But I am getting below error:
C:/prg/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
cannot find -lsqlite3
collect2.exe: error: ld returned 1 exit status
What am I doing wrong?
Upvotes: 1
Views: 454
Reputation:
After some trial and error, it's resolved now and for the benefit of others, here are the steps:
Downloaded the one for 64-bit - sqlite-dll-win64-x64-3240000.zip and extracted to C:\sqlite folder
Converted the sqlite3.def file to sqlite3.lib by using Developer Command Prompt for VS 2017 and executing /def:sqlite3.def /out:sqlite3.lib /MACHINE:X64
command from C:\sqlite folder
This time, the command gcc test.c -o test -I\sqlite -L\sqlite -l sqlite3
from C:\proj folder was successful.
Opened database successfully
Upvotes: 2
Reputation: 409176
You tell gcc
to look for header files in a non-standard location with the -I
(upper-case i) option, but nowhere do you tell gcc
to look for libraries in a non-standard location using the -L
option.
If the libraries are in C:\sqlite\lib
then add -LC:\sqlite\lib
to the command-line before the -l
(lower-case L) option.
Upvotes: 0