你如何正确安装SOCI?

时间:2011-12-11 20:18:02

标签: c++ shared-libraries soci

我正面临着一个烦人的问题,这个问题一直困扰着编程。我打算开始一个个人项目,我需要使用数据库来存储某些信息,我决定使用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编译之后)这样的程序:

TEST.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:无法打开共享对象文件:没有这样的文件或目录。”但是看install log我可以清楚地看到已经安装了共享库。

2 个答案:

答案 0 :(得分: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。解决问题的快速而肮脏的黑客是在那里列出的任何其他文件夹中创建一个smylink到libsoci_sqlite3.so.3.1,但我很确定有更好的方法来修复它。

答案 1 :(得分: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 /本地/ lib64下/