ok6410移植sqlite3

前端之家收集整理的这篇文章主要介绍了ok6410移植sqlite3前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

转自:http://blog.chinaunix.net/space.PHP?uid=26310563&do=blog&id=3023475

开发环境Redhat9kernel2.4.20||Fedora8kernel2.6.23,友善之臂mini2440arm-linux-gcc4.3.2

下载sqlite最新版本3.7.9http://www.sqlite.org/download.html

源码包:sqlite-autoconf-3070900.tar.gz

解压源码包到/opt目录下:

#tarxvzfsqlite-autoconf-3070900.tar.gzC/opt/

建立makeinstall目录

#mkdir/opt/build 进入解压出得文件夹中:

#cd/opt/sqlite-autoconf-3070900 执行configure命令,生成Makefile文件

#./configure-host=arm-linuxprefix=/opt/build 生成Makefile文件后,执行make命令:

#make 使用arm-linux-gcc 4.3.2版本执行make后会有错误提示,终止编译,命令行打印信息如下(后来使用arm-linux-gcc 4.4.3版本无错误提示,可以直接完成编译):

/bin/sh./libtool--tag=CC--mode=compilearm-linux-gcc-DPACKAGE_NAME=\"sqlite\"-DPACKAGE_TARNAME=\"sqlite\"-DPACKAGE_VERSION=\"3.7.9\"-DPACKAGE_STRING=\"sqlite\3.7.9\"-DPACKAGE_BUGREPORT=\"http://www.sqlite.org\"-DPACKAGE_URL=\"\"-DPACKAGE=\"sqlite\"-DVERSION=\"3.7.9\"-D_FILE_OFFSET_BITS=64-DSTDC_HEADERS=1-DHAVE_SYS_TYPES_H=1-DHAVE_SYS_STAT_H=1-DHAVE_STDLIB_H=1-DHAVE_STRING_H=1-DHAVE_MEMORY_H=1-DHAVE_STRINGS_H=1-DHAVE_INTTYPES_H=1-DHAVE_STDINT_H=1-DHAVE_UNISTD_H=1-DHAVE_DLFCN_H=1-DHAVE_FDATASYNC=1-DHAVE_USLEEP=1-DHAVE_LOCALTIME_R=1-DHAVE_GMTIME_R=1-DHAVE_DECL_STRERROR_R=1-DHAVE_STRERROR_R=1-DHAVE_POSIX_FALLOCATE=1-I.@am__isrc@-D_REENTRANT=1-DsqlITE_THREADSAFE=1-DsqlITE_ENABLE_FTS3-DsqlITE_ENABLE_RTREE-g-O2-MTsqlite3.lo-MD-MP-MF.deps/sqlite3.Tpo-c-osqlite3.losqlite3.c

mkdir.libs

arm-linux-gcc-DPACKAGE_NAME=\"sqlite\"-DPACKAGE_TARNAME=\"sqlite\"-DPACKAGE_VERSION=\"3.7.9\""-DPACKAGE_STRING=\"sqlite3.7.9\""-DPACKAGE_BUGREPORT=\"http://www.sqlite.org\"-DPACKAGE_URL=\"\"-DPACKAGE=\"sqlite\"-DVERSION=\"3.7.9\"-D_FILE_OFFSET_BITS=64-DSTDC_HEADERS=1-DHAVE_SYS_TYPES_H=1-DHAVE_SYS_STAT_H=1-DHAVE_STDLIB_H=1-DHAVE_STRING_H=1-DHAVE_MEMORY_H=1-DHAVE_STRINGS_H=1-DHAVE_INTTYPES_H=1-DHAVE_STDINT_H=1-DHAVE_UNISTD_H=1-DHAVE_DLFCN_H=1-DHAVE_FDATASYNC=1-DHAVE_USLEEP=1-DHAVE_LOCALTIME_R=1-DHAVE_GMTIME_R=1-DHAVE_DECL_STRERROR_R=1-DHAVE_STRERROR_R=1-DHAVE_POSIX_FALLOCATE=1-I.@am__isrc@-D_REENTRANT=1-DsqlITE_THREADSAFE=1-DsqlITE_ENABLE_FTS3-DsqlITE_ENABLE_RTREE-g-O2-MTsqlite3.lo-MD-MP-MF.deps/sqlite3.Tpo-csqlite3.c-fPIC-DPIC-o.libs/sqlite3.o

arm-none-linux-gnueabi-gcc:3.7.9":Nosuchfileordirectory

<command-line>:warning:missingterminating"character

查找原因,与前文的make信息-DPACKAGE_STRING=\"sqlite\3.7.9\"相比较,发现是因为"-DPACKAGE_STRING=\"sqlite3.7.9\""字符之间空格没有转义字符\(之后发现是使用交叉编译器arm-linux-gcc4.3.2会出现这个错误)。

修改Makefile文件

#vimMakefile 136行找到-DPACKAGE_STRING=\"sqlite\3.7.9\"改为-DPACKAGE_STRING=\"sqlite_3.7.9\",保存退出

重新执行make指令,建议在make之前先makeclean

等一段时间后,make成功。执行命令:

#makeinstall 完成之后可以发现,之前所建目录/opt/build生成binincludelibshare四个目录。主要用到的文件./bin/sqlite3,./include/sqlite3.h以及./lib/下的库文件

bin文件夹下的sqlite3,是sqlite可执行应用程序,下载到板子Linux系统下的/bin目录或者/usr/bin目录下,并添加文件可执行权限。在板子Linux系统命令行下执行:

[root@FriendlyARMbin]#chmod+xsqlite3 进入sqlite命令行,可以实现对数据库的管理。

[root@FriendlyARMplg]#sqlite3

sqliteversion3.7.92011-11-0100:52:41Enter".help"forinstructionsEntersqlstatementsterminatedwitha";"sqlite> 提示:要成功在arm开发板运行sqlite3,需要把./lib下的动态链接库下载到板子上。否则会有无法找到动态链接libsqlite3.so.0的错误提示

./include/sqlite3.h定义了sqliteAPI接口,会在有关sqlitec文件交叉编译时用到。

./lib/文件夹下是有关sqlite的静态链接库和动态链接

#lslib/libsqlite3.alibsqlite3.lalibsqlite3.solibsqlite3.so.0libsqlite3.so.0.8.6pkgconfig libsqlite3.solibsqlite3.so.0都是libsqlite3.so.0.8.6的软链接文件。真正需要下载到板子目录/lib下的动态库是libsqlite3.so.0.8.6。下载到板子后,还需对它建立软链接文件,因为可执行程序寻找的动态链接库的名字为libsqlite3.so.0

[root@FriendlyARMplg]#ln -s /lib/libsqlite3.so.0.8.6 /lib/libsqlite3.so.0 到此,sqlite的移植工作已经完成!下面进行测试。

测试程序test_sqlite.c如下:

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

  3. staticintcallback(void*NotUsed,intargc**argv*azColName)
  4. {
  5. inti;
  6. for(i=0;i<argc+{
  7. printf("%s = %s\n"[i]?argv:"NULL")}
  8. printf"\n";
  9. return 0}

  10. intmain{
  11. sqlite3*db;
  12. char*zErrMsg;
  13. intrcif(argc!=3{
  14. fprintf(stderr"Usage: %s DATABASE sql-STATEMENT\n"[0}
  15. rc=sqlite3_open(argv[1&db(rc"Can't open database: %s\n"sqlite3_errmsg(db;
  16. sqlite3_close=sqlite3_exec[20&zErrMsg(rc!=sqlITE_OK"sql error: %s\n"}
  17. sqlite3_close}

动态编译:

#arm-linux-gcc-otesttest_sqlite.c-I/opt/build/include/-L/opt/build/lib/-lsqlite3 注:-I制定优先搜索文件路径,-L制定编译的时候,优先搜索库的路径。

下载到板子上执行:

[root@FriendlyARMplg]#./testxyz.db"createtabletbl0(namevarchar(10),number

smallint);"

[root@FriendlyARMplg]#./testxyz.db"insertintotbl0values('cyc',1);"

[root@FriendlyARMplg]#./testxyz.db"insertintotbl0values('dzy',2);"

[root@FriendlyARMplg]#./testxyz.db"select*fromtbl0;"

name=cyc

number=1

name=dzy

number=2

测试成功!

静态编译:

#arm-linux-gcc-otesttest_sqlite.c-I/opt/build/include/-L /opt/build/lib/-static-lsqlite3

/opt/build/lib//libsqlite3.a(sqlite3.o):Infunction`unixDlSym':

/opt/sqlite-autoconf-3070900/sqlite3.c:29926:undefinedreferenceto`dlsym'

/opt/build/lib//libsqlite3.a(sqlite3.o):Infunction`pthreadMutexLeave':

/opt/sqlite-autoconf-3070900/sqlite3.c:17807:undefinedreferenceto`pthread_mutex_unlock'

/opt/build/lib//libsqlite3.a(sqlite3.o):Infunction`pthreadMutexTry':

/opt/sqlite-autoconf-3070900/sqlite3.c:17769:undefinedreferenceto`pthread_mutex_trylock'

/opt/build/lib//libsqlite3.a(sqlite3.o):Infunction`pthreadMutexEnter':

/opt/sqlite-autoconf-3070900/sqlite3.c:17723:undefinedreferenceto`pthread_mutex_lock'

/opt/build/lib//libsqlite3.a(sqlite3.o):Infunction`pthreadMutexFree':

/opt/sqlite-autoconf-3070900/sqlite3.c:17680:undefinedreferenceto`pthread_mutex_destroy'

/opt/build/lib//libsqlite3.a(sqlite3.o):Infunction`pthreadMutexAlloc':

/opt/sqlite-autoconf-3070900/sqlite3.c:17654:undefinedreferenceto`pthread_mutex_init'

/opt/sqlite-autoconf-3070900/sqlite3.c:17637:undefinedreferenceto`pthread_mutexattr_init'

/opt/sqlite-autoconf-3070900/sqlite3.c:17638:undefinedreferenceto`pthread_mutexattr_settype'

/opt/sqlite-autoconf-3070900/sqlite3.c:17639:undefinedreferenceto`pthread_mutex_init'

/opt/sqlite-autoconf-3070900/sqlite3.c:17640:undefinedreferenceto`pthread_mutexattr_destroy'

/opt/build/lib//libsqlite3.a(sqlite3.o):Infunction`unixDlClose':

/opt/sqlite-autoconf-3070900/sqlite3.c:29930:undefinedreferenceto`dlclose'

/opt/build/lib//libsqlite3.a(sqlite3.o):Infunction`unixDlError':

/opt/sqlite-autoconf-3070900/sqlite3.c:29899:undefinedreferenceto`dlerror'

/opt/build/lib//libsqlite3.a(sqlite3.o):Infunction`unixDlOpen':

/opt/sqlite-autoconf-3070900/sqlite3.c:29885:undefinedreferenceto`dlopen'

collect2:ldreturned1exitstatus

错误信息中提示有线程接口函数,需要线程的动态链接库,要加入-lpthread选项。在网上查找,按照网友提供的资料dlopen(),dlclose(),dlerror(),dlsym()函数在头文件#include<dlfcn.h>中,同样需要添加编译选项-ldl

#arm-linux-gcc-otesttest.c-I/opt/build/include/-L/opt/build/lib -static-lsqlite3-lpthreadldl

编译成功,但有一个warning,没有解决,暂时没有发现这个警告对程序影响。

/opt/build/lib/libsqlite3.a(sqlite3.o):Infunction`unixDlOpen':

/opt/sqlite-autoconf-3070900/sqlite3.c:29885:warning:Using'dlopen'instaticallylinkedapplicationsrequiresatruntimethesharedlibrariesfromtheglibcversionusedforlinking

静态编译与动态编译的差别在于,可执行文件较大,即使板子上没有移植动态链接libsqlite3.so.0,程序也同样可以执行。

原文链接:https://www.f2er.com/sqlite/201733.html

猜你在找的Sqlite相关文章