gpt4 book ai didi

c++ - 如何正确安装 SOCI?

转载 作者:可可西里 更新时间:2023-11-01 18:38:45 36 4
gpt4 key购买 nike

我正面临一个烦人的问题,这个问题让我有一段时间没有编程了。我打算开始一个个人项目,在这个项目中我需要使用数据库来存储某些信息,我决定使用 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:无法打开共享对象文件:没有这样的文件或目录。”但看着 install log我可以清楚地看到共享库已安装。

最佳答案

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

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以及。解决问题的一个快速而肮脏的 hack 是在列出的任何其他文件夹中创建一个指向 libsoci_sqlite3.so.3.1 的 smylink,但我很确定有更好的方法来修复它.

关于c++ - 如何正确安装 SOCI?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8467136/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com