gcc --sqlite

来源:互联网 发布:什么叫域名过期 编辑:程序博客网 时间:2024/05/16 04:26

在编译的过程中,出现了一些错误,分析如下:

1. 错误现象一

错误现象:

在第一次使用sqlite数据库时候,通常会出现如下错误:

./simple: error while loading shared libraries: libsqlite3.so.0: cannot open shared object file: No such file or directory

 

错误原因:

这个原因就是在应用程序执行的时候找不到libsqlite3.so.0库文件的路径。

 

解决办法:

 

方法一

修改Linux系统文件/etc/ld.so.conf,添加sqlite库文件位置 /usr/local/lib 到此文件里面。然后重起或者运行ldconfig 重新读取配置。

其本质就是告诉系统动态连接库的目录。

 

方法二

在编译的时候,使用静态编译的方法。那么,就不需要添加静态库。例;

 

[root@localhost bld]# gcc -static test.c -o  test  -lsqlite3

[root@localhost bld]# ls -l test

-rwxr-xr-x    1 root     root      1436081  3  8 19:44 test

可以发现test可执行文件有1.4M,在嵌入式开发中不适合。

 

 

注意:

如果不确定libsqlite3.so.0是否在/usr/local/lib,首先到此目录下查看。

通过 locate libsqlite3.so.0命令查找,发现libsqlite3.so.0不在此目录下,那么,将相应的目录添加到/etc/ld.so.conf, 通过ldconfig更新动态库即可。

2 错误现象二

错误现象:

出现如下类似错误,找不到sqlite3_***操作函数。

/bld/simple.o: In function `main':
/bld/simple.o (.text+0xd5): undefined reference to `sqlite3_open'
/bld/simple.o: undefined reference to `sqlite3_errmsg'
/bld/simple.o: undefined reference to `sqlite3_close'
/bld/simple.o: undefined reference to `sqlite3_exec'
/bld/simple.o: undefined reference to `sqlite3_close'

 

错误原因及解决办法:

1)在编译的时候忘记执行make install一步,导致库文件没有被放置到正确的地方。

2)能是编译时候configure没有配置正确,导致在后期的make操作将sqlite编译出问题。

3)没有正确找到库文件。可以使用如下的方式将其全部路径加入编译命令中。行如:

gcc simple.c -o simple -L/< your directory>/bld/.libs/ -lsqlite3

 

注意:

如果不确定sqlite3库文件的具体位置,可以使用locate sqlite3 查找其具体位置,但要注意是放置库文件的地方。

原创粉丝点击