如何在 windows 10 上正确安装 SOCI c++ 库?
How to properly install SOCI c++ library on windows 10?
我想用 C++ 编写数据库代码。 What modern C++ libraries should be in my toolbox? shows that SOCI is a good library which is cross-platform and free. But the installation of SOCI is a big issue, since I can't find a good blog or tutorial or article or anything giving a detailed rundown. I followed the instructions on the SOCI official page http://soci.sourceforge.net/doc/3.2/installation.html but after succesfully (kinda since it doesn't detect boost. so I had to run it without boost) running cmake, when I build the .sln in visual studio, it gives me 4 errors. I tried everything for days, but nothing seems to work. There is just one video on yt https://www.youtube.com/watch?v=gFGLKaDnwmI,但它显示了一种方法,您必须在 lib 文件中操作微处理器。我不想那样做。而且由于我认为它是一个知名且受欢迎的库,所以我不必那样做。无论如何,构建 o/p 太大了,所以我发布了我得到的错误。第一个出现了三次。所以,这就是为什么我认为我在最终结果中得到 4 个失败。
5>C:\Program Files (x86)\Windows Kits\Include.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\include.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 版本)。
显然这个问题不仅仅与 SOCI 有关。在寻找解决方案时,我遇到了很多与 VS17 有相同问题的其他库。 https://github.com/robotology/icub-firmware-shared/issues/25 https://forum.juce.com/t/solved-error-with-vs2015-regarding-snprintf/14831 到 link 几个。
似乎在某些版本之后 'snprintf' 被添加到 VS(标准库)。所以它与所有使用它的库的宏冲突。
解决它的唯一方法是手动更改宏的名称(如视频中所示)或编辑宏定义(我这样做并且更喜欢因为它更干净)如下:
#define snprintf _snprintf
致:
#if _MSC_VER < 1900
#define snprintf _snprintf
#endif
这消除了我所有的错误,解决方案构建成功,没有任何错误。
我不知道为什么维护人员没有对库本身进行更改来避免这种情况。我希望与他们取得联系,并要求他们也这样做。
希望这对任何图书馆有类似问题的人有所帮助。
我想用 C++ 编写数据库代码。 What modern C++ libraries should be in my toolbox? shows that SOCI is a good library which is cross-platform and free. But the installation of SOCI is a big issue, since I can't find a good blog or tutorial or article or anything giving a detailed rundown. I followed the instructions on the SOCI official page http://soci.sourceforge.net/doc/3.2/installation.html but after succesfully (kinda since it doesn't detect boost. so I had to run it without boost) running cmake, when I build the .sln in visual studio, it gives me 4 errors. I tried everything for days, but nothing seems to work. There is just one video on yt https://www.youtube.com/watch?v=gFGLKaDnwmI,但它显示了一种方法,您必须在 lib 文件中操作微处理器。我不想那样做。而且由于我认为它是一个知名且受欢迎的库,所以我不必那样做。无论如何,构建 o/p 太大了,所以我发布了我得到的错误。第一个出现了三次。所以,这就是为什么我认为我在最终结果中得到 4 个失败。
5>C:\Program Files (x86)\Windows Kits\Include.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\include.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 版本)。
显然这个问题不仅仅与 SOCI 有关。在寻找解决方案时,我遇到了很多与 VS17 有相同问题的其他库。 https://github.com/robotology/icub-firmware-shared/issues/25 https://forum.juce.com/t/solved-error-with-vs2015-regarding-snprintf/14831 到 link 几个。
似乎在某些版本之后 'snprintf' 被添加到 VS(标准库)。所以它与所有使用它的库的宏冲突。
解决它的唯一方法是手动更改宏的名称(如视频中所示)或编辑宏定义(我这样做并且更喜欢因为它更干净)如下:
#define snprintf _snprintf
致:
#if _MSC_VER < 1900
#define snprintf _snprintf
#endif
这消除了我所有的错误,解决方案构建成功,没有任何错误。
我不知道为什么维护人员没有对库本身进行更改来避免这种情况。我希望与他们取得联系,并要求他们也这样做。
希望这对任何图书馆有类似问题的人有所帮助。