有关嵌入式sqlite数据库本地访问的程序(编译出错)!
我已经交叉编译了一个可以在ARM上运行的数据库sqlite,放在挂载在开发板上的目录下,已经在开发板上可以运行(命令行运行过),现在我写了个本地访问的程序,如下:
#include <stdio.h>
#include <string.h>
#include "sqlite.h"
#define SQLITE_OK 0
/*typedef struct sqlite sqlite;*/
int callback(void *datarow,int num_fields,char * * p_fields,char * * p_col_names)
{int i;
int *p_rn=(int *)datarow;
/* (p_rn)++;*/
for(i=0;i<num_fields;i++)
{printf("%s|",p_fields);
}
return 0;
}
main()
{ int revalue;
sqlite * db;
FILE * file;
int row=0;
char * * erromsg;
char * sqlselect="select * from tbll;";
char * sqlcreate="create table tbll(name varchar(10),two smallint(20));";
if ((file=fopen("./testdbs","r+")==NULL)
{ printf("Cannot open database file!\n"
printf("Create the database file ...\n"
db=sqlite_open("./testdbs",0777,0);
sqlite_exec(db,sqlcreate,0,0,0);
printf("The database file have been create!\n"
sqlite_close(db);
}
db=sqlite_open("./testdbs",0777,0);
revalue=sqlite_exec(db,sqlselect,callback,&row,erromsg);
if(revalue!=SQLITE_OK)
{printf("View database testdbs failed!\n"
}
else
{printf("Success!"
}
sqlite_close(db);
fclose(file);
}
但是,在用arm-linux-gcc编译它时通不过,这是怎么回事??
[root@localhost arm_linux_sqlite]# ls
attach.lo build.lo date.o func.o libtool opcodes.o parse.o random.o sqlitetest.o trigger.o vdbeaux.o
attach.o build.o delete.lo hash.lo main.lo os.lo parse.out select.lo table.lo update.lo vdbe.lo
auth.lo config.h delete.o hash.o main.o os.o parse.y select.o table.o update.o vdbe.o
auth.o config.log encode.lo insert.lo Makefile pager.lo pragma.lo sqlite testdb util.lo where.lo
btree.lo config.status encode.o insert.o Makefilesqlite pager.o pragma.o sqlite.h testdbs util.o where.o
btree.o copy.lo expr.lo lemon opcodes.c parse.c printf.lo sqlite.pc tokenize.lo vacuum.lo
btree_rb.lo copy.o expr.o lempar.c opcodes.h parse.h printf.o sqlitetest.c tokenize.o vacuum.o
btree_rb.o date.lo func.lo libsqlite.la opcodes.lo parse.lo random.lo sqlitetestfile trigger.lo vdbeaux.lo
[root@localhost arm_linux_sqlite]# arm-linux-gcc -o sqlitetest sqlitetest.o
sqlitetest.o: In function `main':
sqlitetest.o(.text+0xec): undefined reference to `sqlite_open'
sqlitetest.o(.text+0x110): undefined reference to `sqlite_exec'
sqlitetest.o(.text+0x120): undefined reference to `sqlite_close'
sqlitetest.o(.text+0x134): undefined reference to `sqlite_open'
sqlitetest.o(.text+0x15: undefined reference to `sqlite_exec'
sqlitetest.o(.text+0x1ac): undefined reference to `sqlite_close'
collect2: ld returned 1 exit status
[root@localhost arm_linux_sqlite]#
清高手指点.sqlitetest.c
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
因为没有指定 sqlite 的库文件, 于是ld 就联接不到 sqlite_* 之类的函数。
arm-linux-gcc -o sqlitetest sqlitetest.o -lsqlite
^^^^^
http://www.linuxsir.org/bbs/archive/index.php/t-162579.html