加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

在 Solaris 10 系统上编译并使用SQLite-3.4.2

发布时间:2020-12-12 23:39:59 所属栏目:百科 来源:网络整理
导读:作者:zieckey (zieckey@yahoo.com.cn) All Rights Reserved! 1、引言 其实Solaris 10 上自带了SQLite,其可执行文件是 /lib/svc/bin/sqlite 这里就可以测试下: bash-3.00# /lib/svc/bin/sqlite SQLite version 2.8.15-repcached-Generic Patch Enter "

/*
** name :testsqlite.c
** This file is used to test C/C++ API for sqlite
** Author : zieckey
** Date : 2006/04/11
*/

#include <stdio.h>
#include <sqlite3.h>

int main( void )
{
sqlite3 *db=NULL;
char *zErrMsg = 0;
int rc;
rc = sqlite3_open("zieckey.db", &db); //打开指定的数据库文件,如果不存在将创建一个同名的数据库文件

if( rc ){
fprintf(stderr, "Can't open database: %s/n", sqlite3_errmsg(db));
sqlite3_close(db);
exit(1);
}
else printf("open zieckey.db successfully!/n");

sqlite3_close(db); //关闭数据库

return 0;
}

上面C程序保存为 testsqlite.c 文件,

bash-3.00# gcc testsqlite.c
testsqlite.c:8:21: sqlite3.h: 无此文件或目录
testsqlite.c: In function `main':
testsqlite.c:12: error: `sqlite3' undeclared (first use in this function)
testsqlite.c:12: error: (Each undeclared identifier is reported only once
testsqlite.c:12: error: for each function it appears in.)
testsqlite.c:12: error: `db' undeclared (first use in this function)
testsqlite.c:25:2: warning: no newline at end of file
bash-3.00# gcc testsqlite.c -lsqlite3
testsqlite.c:8:21: sqlite3.h: 无此文件或目录
testsqlite.c: In function `main':
testsqlite.c:12: error: `sqlite3' undeclared (first use in this function)
testsqlite.c:12: error: (Each undeclared identifier is reported only once
testsqlite.c:12: error: for each function it appears in.)
testsqlite.c:12: error: `db' undeclared (first use in this function)
testsqlite.c:25:2: warning: no newline at end of file
bash-3.00# gcc testsqlite.c -lsqlite3 -I.
testsqlite.c:25:2: warning: no newline at end of file
ld: 致命的: 库 -lsqlite3: 没有找到
ld: 致命的: 文件处理错误。无输出写到a.out
collect2: ld returned 1 exit status
bash-3.00# gcc testsqlite.c -lsqlite3 -I. -L.
testsqlite.c:25:2: warning: no newline at end of file
bash-3.00# ls
a.out libsqlite3.so shell.c sqlite3 sqlite3.c sqlite3.h testsqlite.c zieckey.db
bash-3.00# ./a.out
open zieckey.db successfully! 好了终于成功了!恭喜你! 关于上面的一些错误问题的解决办法的详细解释见“参考文档1”。 参考文档:
1、 http://blog.chinaunix.net/u/16292/showart_108145.html
2、 http://www.sqlite.org/cvstrac/wiki?p=HowToCompile

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

作者:zieckey (zieckey@yahoo.com.cn)
All Rights Reserved!
1、引言 其实Solaris 10 上自带了SQLite,其可执行文件是 /lib/svc/bin/sqlite
这里就可以测试下:
bash-3.00# /lib/svc/bin/sqlite
SQLite version 2.8.15-repcached-Generic Patch
Enter ".help" for instructions
sqlite> 发现这个版本有点老,2.8.15 但是我通过find命令并没有找到SQLite的动态共享库,
所以我决定自己编译一个最新的SQLite 2、下载 在SQLite的官方网址 http://www.sqlite.org/download.html 下载,
这里我下载了源码的这个包:sqlite-amalgamation-3_4_2.zip
该包将SQLite数据库的所有源代码集中在一个 sqlite3.c C源文件和 sqlite3.h 头文件,
这样就非常便于我们编译,特别是对于Mikefile文件规则不熟悉的人。 3、编译 bash-3.00# cd sqlite/
bash-3.00# ls
sqlite3.c sqlite3.h 2.1 编译SQLite3的命令行工具文件,
它是一个使用SQLite库去操作SQLite数据库文件的独立文件,
编译它需要一个 shell.c 文件,
这个文件可以从 http://www.sqlite.org/cvstrac/fileview?f=sqlite/src/shell.c&v=1.166
处得到一个拷贝,好了,命令如下: bash-3.00# gcc shell.c sqlite3.c -o sqlite3
bash-3.00# ls
shell.c sqlite3 sqlite3.c sqlite3.h
输出文件也就是SQLite3的命令行工具文件被命名为:sqlite3 2.2 编译动态共享库文件
bash-3.00# gcc -c sqlite3.c -o libsqlite3.so
bash-3.00# ls
libsqlite3.so shell.c sqlite3 sqlite3.c sqlite3.h
输出文件也就是SQLite3的动态链接库文件被命名为:libsqlite3.so 4、测试: 4.1 SQLite3的命令行工具测试 继续在当前目录下进行
bash-3.00# ./sqlite3 zieckey.db
SQLite version 3.4.2
Enter ".help" for instructions
sqlite> .exit
bash-3.00# 可以看到上面是SQLite3的命令行工具执行任务成功 4.2 编写C测试程序测试动态链接库文件 这里我给出一个简单的程序:
    推荐文章
      热点阅读