7

我正面临一个烦人的问题,这个问题一直阻碍我编程一段时间。我打算开始一个个人项目,在这个项目中我需要使用数据库来存储某些信息,我决定使用 SQLite,但是我不喜欢 C-ish API,所以我在 SQLite wiki 中遇到了 SOCI 包装器。

我去了 SOCI 官方网站,阅读了文档并决定试一试。我按照文档的“安装”一章中的说明进行操作,在安装完所有要求后,我编译并安装了它:

cmake -DWITH_BOOST=ON -DSOCI_TESTS=ON -DWITH_SQLITE3=ON
make
make test
sudo make install

但是,当尝试运行(使用 编译后g++ test.cpp -o1 -lsoci_core -lsoci_sqlite3)诸如以下程序的程序时,所有测试都成功完成:

测试.cpp:

#include "soci/soci.h"
#include "soci/sqlite3/soci-sqlite3.h"
#include <iostream>

int main()
{
    soci::session sql(soci::sqlite3, "testdb.db");

    return 0;    
}

我收到一条错误消息:“加载共享库时出错:libsoci_sqlite3.so.3.1:无法打开共享对象文件:没有这样的文件或目录。” 但是查看安装日志我可以清楚地看到共享库已安装。

4

2 回答 2

3

我相信我已经找到了问题所在。做一个:

strace -e open ./1 2>&1 | grep soci

输出以下内容:

open("/usr/local/lib/libsoci_core.so.3.1", O_RDONLY) = 3
open("/lib/x86_64-linux-gnu/tls/x86_64/libsoci_sqlite3.so.3.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/tls/libsoci_sqlite3.so.3.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/x86_64/libsoci_sqlite3.so.3.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/libsoci_sqlite3.so.3.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/lib/x86_64-linux-gnu/tls/x86_64/libsoci_sqlite3.so.3.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/lib/x86_64-linux-gnu/tls/libsoci_sqlite3.so.3.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/lib/x86_64-linux-gnu/x86_64/libsoci_sqlite3.so.3.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/lib/x86_64-linux-gnu/libsoci_sqlite3.so.3.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/lib/tls/x86_64/libsoci_sqlite3.so.3.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/lib/tls/libsoci_sqlite3.so.3.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/lib/x86_64/libsoci_sqlite3.so.3.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/lib/libsoci_sqlite3.so.3.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/lib/tls/x86_64/libsoci_sqlite3.so.3.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/lib/tls/libsoci_sqlite3.so.3.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/lib/x86_64/libsoci_sqlite3.so.3.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/lib/libsoci_sqlite3.so.3.1", O_RDONLY) = -1 ENOENT (No such file or directory)
./1: error while loading shared libraries: libsoci_sqlite3.so.3.1: cannot open shared object file: No such file or directory

通过查看它,您可以清楚地看到它只搜索/usr/local/lib/soci_core而通常它也应该搜索soci_sqlite3。解决问题的快速而肮脏的技巧是在此处libsoci_sqlite3.so.3.1列出的任何其他文件夹中创建一个 smylink,但我很确定有更好的方法来解决它。

于 2011-12-12T17:22:24.863 回答
0

在您的 SOCI 安装库中,位于 /usr/local/lib64/

以下语句应该有效:

g++ test.cpp -o test -I/usr/local/include/soci -L/usr/local/lib64/ -lsoci_core -lsoci_sqlite3 \ -Wl
,-rpath=/usr/local/lib64/

于 2014-06-01T06:52:57.250 回答