c++ - 如何在 Windows 10 上正确安装 SOCI c++ 库?

标签 c++ database soci

我想用 C++ 编写数据库代码。 What modern C++ libraries should be in my toolbox?表明 SOCI 是一个很好的跨平台免费库。但是 SOCI 的安装是个大问题,因为我找不到好的博客、教程、文章或任何提供详细概述的内容。我按照 SOCI 官方页面上的说明进行操作 http://soci.sourceforge.net/doc/3.2/installation.html但是在成功运行 cmake 之后(有点因为它没有检测到提升。所以我不得不在没有提升的情况下运行它),当我在 visual studio 中构建 .sln 时,它给了我 4 个错误。我尝试了好几天的所有方法,但似乎没有任何效果。 yt上只有一个视频https://www.youtube.com/watch?v=gFGLKaDnwmI ,但它显示了一种方法,您必须在 lib 文件中操作微处理器。我不想那样做。而且由于我认为它是一个知名且受欢迎的库,所以我不必那样做。无论如何,构建 o/p 太大了,所以我已经发布了我得到的错误。第一个出现了三次。所以,这就是为什么我认为我在最终结果中失败了 4。

5>C:\Program Files (x86)\Windows Kits\10\Include\10.0.17134.0\ucrt\stdio.h(1935): fatal error C1189: #error:  Macro definition of snprintf conflicts with Standard Library function declaration

8>LINK : fatal error LNK1104: cannot open file '..\..\..\lib\Debug\libsoci_postgresql_3_2.lib'


========== Build: 8 succeeded, 4 failed, 0 up-to-date, 3 skipped ==========

我还有一个不重要但仅供引用的问题(不要为此标记我。如果你想要我会删除它)。数据库编程不是经常用 C++ 完成吗?或者如果完成了,C++ 编码人员比 C++ 更喜欢 C api 吗?因为,我很难找到与此相关的近期优秀文章或博客。

最佳答案

您要构建什么版本的 soci?我找到了 thread你的错误:

The build fails because there are two included files that redefine the 'snprintf' symbol. The first definition is in "D:\devsrc\soci-3.2.3\core\soci-platform.h" and the second one (which produces the error) is in "C:\Program Files (x86)\Windows Kits\10\include\10.0.10150.0\ucrt\stdio.h" (a Standard Library file).

To fix the error, comment the line 27 of "D:\devsrc\soci-3.2.3\core\soci-platform.h":

// #define snprintf _snprintf

, so that SOCI ignores its own definition and uses that of the Standard Library instead.

但是库的作者指出:

For the record, I have just managed to build SOCI 3.2.3 with VS2015 (CL.EXE version19.00.24215.1) without any problems or modifications required.

git clone https://github.com/SOCI/soci.git git co release/3.2 mkdir _build cd _build cmake ..

then load SOCI.sln with VS2015 and build.

您也可以尝试构建 master分支(又名 4.0.0 版本)。

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

相关文章:

c++ - 如何找出键盘的地址

mysql - 在 SQL 中将元组添加在一起时选择不同

c++ - 修复 lib 兼容性 c++ mingw 和 postgresql

c++ - 如何使用 SOCI C++ Database 库?

c++ - SOCI 的问题

c++ - 为什么隐式转换的结果是 -128?

c++ - vtable:底层算法

c++ - 没有运算符匹配这些操作数

python - (Python/JSON/MySQL) 关于 JSON 格式的财务数据不会传输到数据库的建议

sql - 如何使用 'group by'(或类似的)语句来聚合几个指定的行?