免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1524 | 回复: 2
打印 上一主题 下一主题

有关嵌入式sqlite数据库本地访问的程序(编译出错)! [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-04-23 22:38 |只看该作者 |倒序浏览
我已经交叉编译了一个可以在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

论坛徽章:
0
2 [报告]
发表于 2006-04-24 23:39 |只看该作者
因为没有指定 sqlite 的库文件, 于是ld 就联接不到 sqlite_* 之类的函数。

论坛徽章:
0
3 [报告]
发表于 2006-04-25 01:55 |只看该作者
arm-linux-gcc -o sqlitetest sqlitetest.o -lsqlite
                                                   ^^^^^

http://www.linuxsir.org/bbs/archive/index.php/t-162579.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP