编译C和sqlite3

时间:2017-06-08 01:38:46

标签: c windows gcc sqlite

我在将sqlite3合并到我正在编写的程序中时遇到了一些麻烦。在过去的几天里,我一直在寻找解决方案。我正在使用MinGW编译器,并且已经尝试过:

  • 确保C:\ MinGW \ bin目录包含在用户和系统环境中没有空格且用分号分隔的路径变量

  • 使用命令提示符并输入" C:\ MinGW \ bin \ gcc shell.c sqlite3.c -lpthread -ldl"在所有相关文件的同一目录中返回结果" c:/ mingw / bin /../ lib / gcc / mingw32 / 5.3.0 /../../../../ mingw32 / bin / ld.exe:找不到-ldl collect2.exe:错误:ld返回1退出状态"

  • 全新安装MinGW和eclipse

如果这对我测试的代码有帮助,我就无法将包含显示为代码,但它们都按顺序排列,iostream,stdio.h和sqlite3 。H 它返回错误"致命错误:sqlite3.h:没有这样的文件或目录"。我将所有包含文件放在与.cpp源相同的目录中。

int main(int argc, char* argv[])
{
    sqlite3 *db;
    char *zErrMsg = 0;
    int rc;
    rc = sqlite3_open("text.db", &db);
    return 0;
}

2 个答案:

答案 0 :(得分:1)

#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;
}

编译和测试结果:

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
$

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
$

答案 1 :(得分:0)

在摆弄了一下后,我意识到我所要做的就是#include“sqlite3.h”与源文件目录中的sqlite.h文件,并在项目树中包含sqlite3.c文件。我正在使用DevC ++,我去了项目&gt;添加到项目并选择sqlite3.c文件。然后项目&gt;项目选项&gt;文件并选择sqlite3.c然后取消选中“将文件编译为C ++”。