gpt4 book ai didi

编译 C 和 sqlite3

转载 作者:太空宇宙 更新时间:2023-11-04 03:22:15 24 4
gpt4 key购买 nike

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

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

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

  • 全新安装 MinGW 和 eclipse

如果它有帮助,这是我正在测试的代码,我无法让包含显示为代码,但它们都按顺序放在插入符号中,iostream、stdio.h 和 sqlite3.h它返回错误“ fatal error :sqlite3.h:没有这样的文件或目录”。我也将所有包含文件与 .cpp 源放在同一目录中。

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

最佳答案

#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
$

关于编译 C 和 sqlite3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44425307/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com