如何使用 SOCI C++数据库库?

发布于 2024-10-10 01:27:04 字数 439 浏览 2 评论 0原文

我正在尝试在我的程序中实现社交,但我不知道如何实现。我在 Linux 上的一个使用 netbeans 的项目中使用 C++。我已按照以下步骤操作: http://soci.sourceforge.net/doc/struct.html< /a> 来安装它,我尝试在我的项目中复制 /src/core 中的文件 soci.h 和 /src/backends/mysql 中的 soci-mysql.h 文件,但它给出了编译错误(这些文件包括其他 soci文件,但将所有文件复制到目录中是不合逻辑的...)。我已阅读该指南多次,但我不明白我做错了什么。示例仅包含这些文件。

谢谢。

编辑:我在答案下方的评论中提供了更多信息。我不知道我必须遵循哪些步骤来实施 soci。

I'm trying to implement soci in my program but I don't know how. I'm using C++ on Linux, on a project using netbeans. I have followed the steps in: http://soci.sourceforge.net/doc/structure.html to install it, and I tried to copy the files soci.h from /src/core and soci-mysql.h from /src/backends/mysql in my project but it gives a compilation error (these files include other soci files, but it's illogical to copy all files into the directory...). I have read the guide several time but I don't understand what I'm doing wrong. The examples only include these files.

Thanks.

Edit: I have given more information in a comment below the answer. I don't know what steps I have to follow to implement soci.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

清引 2024-10-17 01:27:04

该页面上的相关位是

当配置脚本不带参数运行时,该过程的其余部分将使用 /usr/local/include/soci 作为 SOCI 头文件和 /usr/ 的默认目标local/lib 作为库文件的默认目标

现在 /usr/local/include 应该位于您的默认包含路径中(例如尝试类似 gcc -c -v -x c++ /dev/null -o /dev /null 以查看安装使用的列表),因此您可以使用这些来包含这些内容

#include <soci/soci.h>
#include <soci/soci-mysql.h>

,然后需要将库添加到链接步骤中。看起来您将拥有库的静态版本和共享版本。您需要将 -lsoci_core -lsoci_mysql 添加到链接步骤中;但是,如果这不起作用,那么您还需要指定 /usr/local/lib 作为搜索目录,即 -L/usr/local/lib -lsoci_core -lsoci_mysql。 (同样,它可能已经存在,但您可以使用 gcc -print-search-dirs 看到。)但是,问题是,如果您使用的是共享版本并且 /usr/local/lib 不是不在您的发行版库搜索路径中(请参阅 /etc/ld.so.conf 和/或 /etc/ld.so.conf.d/*),那么它将无法在运行时找到共享库。您需要使用链接器开关 -rpath 在库的路径中进行硬编码,或者像以前一样或在您的环境中将 /usr/local/lib 添加到系统范围的搜索路径中(变量LD_LIBRARY_PATH)。我不确定最好的方法是什么 - 我建议使用 -rpath 来避免一般情况下修改系统,尽管如果您在 /usr/local 中构建了很多库/lib 添加它可能是有意义的。

The relevant bit on that page is

When the configure script is run without parameters, the remaining part of the process will use /usr/local/include/soci as a default destination for SOCI header files and /usr/local/lib as a default destination for library files

Now /usr/local/include ought to be in your default include path (e.g. try something like gcc -c -v -x c++ /dev/null -o /dev/null to see the list your install uses) and so you can include these using

#include <soci/soci.h>
#include <soci/soci-mysql.h>

You then need to add the libraries to your link step. It looks like you'll have both static and shared versions of the libraries. You'll need to add -lsoci_core -lsoci_mysql to your link step; however if that doesn't work then you'll also need to specify /usr/local/lib as a search directory i.e. -L/usr/local/lib -lsoci_core -lsoci_mysql. (Again it's probably there already but you can see using gcc -print-search-dirs.) However, the issue then is that if you're using the shared version and /usr/local/lib isn't in your distributions library search path (see /etc/ld.so.conf and/or /etc/ld.so.conf.d/*) then it won't be able to find the shared library at runtime. You'll need to either hard-code in the path to the library with the linker switch -rpath or add /usr/local/lib to the system-wide search path as before or in your environment (variable LD_LIBRARY_PATH). I'm not sure what the best way to do this is - I'd suggest -rpath to avoid modifying the system in general, although if you're building a lot of libraries into /usr/local/lib it might make sense to add it.

哆兒滾 2024-10-17 01:27:04

当我执行 session sql("mysql://db=...)

我找到了一个解决方案(至少在我的 Ubuntu 11.04 上),只需这样做:

sudo -i ln -s /usr/lib/libsoci_mysql-gcc-3_0-3.0.0.so /usr/lib/libsoci_mysql.so

似乎 SOCI 库搜索系统中没有的文件 /usr/lib/libsoci_mysql.so,如果您链​​接到,请购买库 /usr/lib/libsoci_mysql-gcc-3_0-3.0.0.so 它在它工作的系统中(我认为 debian/ubuntu 使文件名从原始名称更改,但它有副作用,因为 SOCI 库在内部搜索原始名称),

我使用 bash 环境变量 LD_DEBUG=files 并运行我的 C++ 二进制文件发现了错误

I got the same doesn't load backend error on my C++ program when I execute session sql("mysql://db=...)

I found a solution (at least on my Ubuntu 11.04). Just do:

sudo -i ln -s /usr/lib/libsoci_mysql-gcc-3_0-3.0.0.so /usr/lib/libsoci_mysql.so

It seem that the SOCI library search for the file /usr/lib/libsoci_mysql.so that is not in the system, buy if you make a link to the library /usr/lib/libsoci_mysql-gcc-3_0-3.0.0.so that it's in the system it works (I think debian/ubuntu makes a file name change from the original name, but it have side effects because the SOCI library search inside for the original name).

I found the error using the bash environment variable LD_DEBUG=files and running my C++ binary.

Hope it helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文