sqlite 及其编译问题

在Ubuntu系统中编译sqlite时遇到了链接错误,如`undefined reference to `sqlite3_open'`等。尝试通过添加链接库路径 `-L /usr/local/lib` 和包含头文件的路径 `-I /usr/local/include/` 以及静态链接 `-static` 解决问题。最终成功编译生成了sqlexe可执行文件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

ubuntu@sky:~/sqlite$ gcc sql_get_table.c

/tmp/cc6DoZtO.o: In function `main':

sql_get_table.c:(.text+0x73): undefined reference to `sqlite3_open'

sql_get_table.c:(.text+0x8a): undefined reference to `sqlite3_errmsg'

sql_get_table.c:(.text+0x165): undefined reference to `sqlite3_get_table'

sql_get_table.c:(.text+0x203): undefined reference to `sqlite3_free_table'

sql_get_table.c:(.text+0x215): undefined reference to `sqlite3_close'

collect2: ld returned 1 exit status

ubuntu@sky:~/sqlite$

 

 

 

ubuntu@sky:~/sqlite$ gcc -o sqlexe -L /usr/local/lib -I /usr/local/include/ -static sqlexe.c -lsqlite3

/usr/lib/gcc/i686-linux-gnu/4.6/../../../../lib/libsqlite3.a(sqlite3.o): In function `pthreadMutexTry':

(.text+0x10b6d): undefined reference to `pthread_mutex_trylock'

/usr/lib/gcc/i686-linux-gnu/4.6/../../../../lib/libsqlite3.a(sqlite3.o): In function `pthreadMutexFree':

(.text+0x10b9e): undefined reference to `pthread_mutex_destroy'

/usr/lib/gcc/i686-linux-gnu/4.6/../../../../lib/libsqlite3.a(sqlite3.o): In function `pthreadMutexAlloc':

(.text+0x10bdf): undefined reference to `pthread_mutex_init'

/usr/lib/gcc/i686-linux-gnu/4.6/../../../../lib/libsqlite3.a(sqlite3.o): In function `pthreadMutexAlloc':

(.text+0x10c13): undefined reference to `pthread_mutexattr_init'

/usr/lib/gcc/i686-linux-gnu/4.6/../../../../lib/libsqlite3.a(sqlite3.o): In function `pthreadMutexAlloc':

(.text+0x10c23): undefined reference to `pthread_mutexattr_settype'

/usr/lib/gcc/i686-linux-gnu/4.6/../../../../lib/libsqlite3.a(sqlite3.o): In function `pthreadMutexAlloc':

(.text+0x10c2f): undefined reference to `pthread_mutex_init'

/usr/lib/gcc/i686-linux-gnu/4.6/../../../../lib/libsqlite3.a(sqlite3.o): In function `pthreadMutexAlloc':

(.text+0x10c37): undefined reference to `pthread_mutexattr_destroy'

/usr/lib/gcc/i686-linux-gnu/4.6/../../../../lib/libsqlite3.a(sqlite3.o): In function `unixDlError':

(.text+0x1c1e8): undefined reference to `dlerror'

/usr/lib/gcc/i686-linux-gnu/4.6/../../../../lib/libsqlite3.a(sqlite3.o): In function `unixDlSym':

(.text+0x2334): undefined reference to `dlsym'

 

 

ubuntu@sky:~/sqlite$ gcc -o sqlexe -L /usr/local/lib -I /usr/local/include/ -static-libgfortran sqlexe.c -lsqlite3

ubuntu@sky:~/sqlite$ ls

libsqlite3-0_3.7.2-1ubuntu0.1_i386.deb    sqlexe    sql_get_table    sqlite3_3.7.2-1ubuntu0.1_i386.deb

libsqlite3-dev_3.7.2-1ubuntu0.1_i386.deb  sqlexe.c  sql_get_table.c  test.db

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值