Real210 编译sqlite错误:.//libsqlite3.a(sqlite3.o): In function `unixDlSym’:

往往在静态链接sqlite库文件的时候,会报这个错误:

.//libsqlite3.a(sqlite3.o): In function `unixDlSym':

...

[root@localhost testdb]# arm-linux-gcc testdb.c -L./ -lsqlite3 -static -o testdb 
.//libsqlite3.a(sqlite3.o): In function `unixDlSym':
/root/sqlite-autoconf-3070900/sqlite3.c:29926: undefined reference to `dlsym'
.//libsqlite3.a(sqlite3.o): In function `pthreadMutexLeave':
/root/sqlite-autoconf-3070900/sqlite3.c:17807: undefined reference to `pthread_mutex_unlock'
.//libsqlite3.a(sqlite3.o): In function `pthreadMutexTry':
/root/sqlite-autoconf-3070900/sqlite3.c:17769: undefined reference to `pthread_mutex_trylock'
.//libsqlite3.a(sqlite3.o): In function `pthreadMutexEnter':
/root/sqlite-autoconf-3070900/sqlite3.c:17723: undefined reference to `pthread_mutex_lock'
.//libsqlite3.a(sqlite3.o): In function `pthreadMutexFree':
/root/sqlite-autoconf-3070900/sqlite3.c:17680: undefined reference to `pthread_mutex_destroy'
.//libsqlite3.a(sqlite3.o): In function `pthreadMutexAlloc':
/root/sqlite-autoconf-3070900/sqlite3.c:17654: undefined reference to `pthread_mutex_init'
/root/sqlite-autoconf-3070900/sqlite3.c:17637: undefined reference to `pthread_mutexattr_init'
/root/sqlite-autoconf-3070900/sqlite3.c:17638: undefined reference to `pthread_mutexattr_settype'
/root/sqlite-autoconf-3070900/sqlite3.c:17639: undefined reference to `pthread_mutex_init'
/root/sqlite-autoconf-3070900/sqlite3.c:17640: undefined reference to `pthread_mutexattr_destroy'
.//libsqlite3.a(sqlite3.o): In function `unixDlClose':
/root/sqlite-autoconf-3070900/sqlite3.c:29930: undefined reference to `dlclose'
.//libsqlite3.a(sqlite3.o): In function `unixDlError':
/root/sqlite-autoconf-3070900/sqlite3.c:29899: undefined reference to `dlerror'
.//libsqlite3.a(sqlite3.o): In function `unixDlOpen':
/root/sqlite-autoconf-3070900/sqlite3.c:29885: undefined reference to `dlopen'
collect2: ld returned 1 exit status

解决的办法是给加上编译参数-ldl -lpthread这两个编译参数,也就是按照下面编译命令:

arm-linux-gcc testdb.c -L./ -static -lsqlite3 -lpthread -ldl -o testdb

上面这个编译命令还是会有警告的,如下所示:

[root@localhost testdb]# arm-linux-gcc testdb.c -L./ -static -lsqlite3 -lpthread -ldl -o testdb
.//libsqlite3.a(sqlite3.o): In function `unixDlOpen':
/root/sqlite-autoconf-3070900/sqlite3.c:29885: warning: Using 'dlopen' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
[root@localhost testdb]#

但是不影响sqlite的使用.

参考:http://stackoverflow.com/questions/3463438/sqlite-undefined-reference-to-sqlite3-open-error-in-netbeans-c-on-ubuntu-in

Sqlite undefined reference to `sqlite3_open' error in Netbeans C++ on Ubuntu, Integrating SQLite into Netbeans C++ Ubuntu - Stack Overflow

文章的脚注信息由WordPress的wp-posturl插件自动生成



|2|left
打赏

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: