Reputation: 43
I'm having some trouble incorporating sqlite3 into a program I'm writing. I've been scouring the internet over the past few days attempting to find a solution. I'm using the MinGW compiler and have already tried:
Ensuring the C:\MinGW\bin directory is included in both the user and system environment Path variables with no spaces and separated with a semi-colon
Using the command prompt and entering "C:\MinGW\bin\gcc shell.c sqlite3.c -lpthread -ldl" in the same directory of all related files which returns the result "c:/mingw/bin/../lib/gcc/mingw32/5.3.0/../../../../mingw32/bin/ld.exe: cannot find -ldl collect2.exe: error: ld returned 1 exit status"
Fresh install of MinGW and eclipse
If it helps this is the code I'm testing this with, I can't get the includes to show up as code but they are all in carets in order, iostream, stdio.h, and sqlite3.h It returns the error "fatal error: sqlite3.h: No such file or directory". I have all of the include files in the same directory as the .cpp source as well.
int main(int argc, char* argv[])
{
sqlite3 *db;
char *zErrMsg = 0;
int rc;
rc = sqlite3_open("text.db", &db);
return 0;
}
Upvotes: 2
Views: 1303
Reputation: 43
After fiddling around a bit I realized all I had to do was #include "sqlite3.h" with the sqlite.h file in the source file directory and include the sqlite3.c file in the project tree. I'm using DevC++ and I went to project > add to project and select the sqlite3.c file. Then project > project options > files and select sqlite3.c then uncheck "compile file as C++".
Upvotes: 0
Reputation: 223
#include <stdio.h>
#include "sqlite3.h"
int main(int argc, char* argv[])
{
sqlite3 *db;
char *zErrMsg = 0;
int rc;
rc = sqlite3_open("text.db", &db);
return 0;
}
Compile and test result:
w00343520@wuhy1w001184171 MINGW64 /d/Download/sqlite-amalgamation-3190200/sqlite-amalgamation-3190200
$ mingw32-gcc -o test main.c sqlite3.c -I./
w00343520@wuhy1w001184171 MINGW64 /d/Download/sqlite-amalgamation-3190200/sqlite-amalgamation-3190200
$ ll
total 8485
-rw-r--r-- 1 w00343520 1049089 192 六月 8 10:38 main.c
-rw-r--r-- 1 w00343520 1049089 236938 五月 26 00:15 shell.c
-rw-r--r-- 1 w00343520 1049089 7130198 五月 26 00:15 sqlite3.c
-rw-r--r-- 1 w00343520 1049089 498184 五月 26 00:15 sqlite3.h
-rw-r--r-- 1 w00343520 1049089 30199 五月 26 00:15 sqlite3ext.h
-rwxr-xr-x 1 w00343520 1049089 785640 六月 8 10:38 test.exe*
w00343520@wuhy1w001184171 MINGW64 /d/Download/sqlite-amalgamation-3190200/sqlite-amalgamation-3190200
$ ./test.exe
w00343520@wuhy1w001184171 MINGW64 /d/Download/sqlite-amalgamation-3190200/sqlite-amalgamation-3190200
$ ll
total 8485
-rw-r--r-- 1 w00343520 1049089 192 六月 8 10:38 main.c
-rw-r--r-- 1 w00343520 1049089 236938 五月 26 00:15 shell.c
-rw-r--r-- 1 w00343520 1049089 7130198 五月 26 00:15 sqlite3.c
-rw-r--r-- 1 w00343520 1049089 498184 五月 26 00:15 sqlite3.h
-rw-r--r-- 1 w00343520 1049089 30199 五月 26 00:15 sqlite3ext.h
-rwxr-xr-x 1 w00343520 1049089 785640 六月 8 10:38 test.exe*
-rw-r--r-- 1 w00343520 1049089 0 六月 8 10:41 text.db
w00343520@wuhy1w001184171 MINGW64 /d/Download/sqlite-amalgamation-3190200/sqlite-amalgamation-3190200
$
The test result for shell.c:
w00343520@wuhy1w001184171 MINGW64 /d/Download/sqlite-amalgamation-3190200/sqlite-amalgamation-3190200
$ mingw32-gcc -o sqlite shell.c sqlite3.c -I./
w00343520@wuhy1w001184171 MINGW64 /d/Download/sqlite-amalgamation-3190200/sqlite-amalgamation-3190200
$ ./sqlite.exe
w00343520@wuhy1w001184171 MINGW64 /d/Download/sqlite-amalgamation-3190200/sqlite-amalgamation-3190200
$ ./sqlite.exe --help
Usage: D:\Download\sqlite-amalgamation-3190200\sqlite-amalgamation-3190200\sqlite.exe [OPTIONS] FILENAME [SQL]
FILENAME is the name of an SQLite database. A new database is created
if the file does not previously exist.
OPTIONS include:
-ascii set output mode to 'ascii'
-bail stop after hitting an error
-batch force batch I/O
-column set output mode to 'column'
-cmd COMMAND run "COMMAND" before reading stdin
-csv set output mode to 'csv'
-echo print commands before execution
-init FILENAME read/process named file
-[no]header turn headers on or off
-help show this message
-html set output mode to HTML
-interactive force interactive I/O
-line set output mode to 'line'
-list set output mode to 'list'
-lookaside SIZE N use N entries of SZ bytes for lookaside memory
-mmap N default mmap size set to N
-newline SEP set output row separator. Default: '\n'
-nullvalue TEXT set text string for NULL values. Default ''
-pagecache SIZE N use N slots of SZ bytes each for page cache memory
-scratch SIZE N use N slots of SZ bytes each for scratch memory
-separator SEP set output column separator. Default: '|'
-stats print memory stats before each finalize
-version show SQLite version
-vfs NAME use NAME as the default VFS
w00343520@wuhy1w001184171 MINGW64 /d/Download/sqlite-amalgamation-3190200/sqlite-amalgamation-3190200
$
Upvotes: 2