简体   繁体   English

在Windows 10上从Visual Studio 2015链接libpqxx

[英]Linking libpqxx from Visual Studio 2015 on Windows 10

I've recently decided to try out PostgreSQL as the database platform for some C++ development I'm working on. 我最近决定尝试将PostgreSQL用作我正在从事的某些C ++开发的数据库平台。 I decided to use libpqxx as the connection library for my project, and quickly found out this would be an uphill battle to do from VS 2015 on a Windows 10 machine. 我决定将libpqxx用作项目的连接库,并很快发现从Windows 10机器上的VS 2015开始这将是艰巨的任务。

After much teeth-gnashing and nail-biting, I have gotten libpqxx to compile on Windows 10. This leaves me with the following directory structure 经过大量的咬和咬之后,我得到了libpqxx在Windows 10上进行编译。这使我拥有以下目录结构

Per libpqxx's documentation, I also placed a copy of libpq.dll in my project's executable directory. 根据libpqxx的文档,我还将libpq.dll的副本放置在项目的可执行目录中。 Please note: I have done this for both debug and release builds, tried to build both, and ended up with the same result. 请注意:我在调试和发布版本中都这样做,试图同时构建它们,并最终得到相同的结果。

All the tutorials I've seen seem to indicate that the library can be used after linking it and simply #including pqxx/pqxx, so I set up a small project to do just that. 我看过的所有教程似乎都表明,链接该库后即可使用该库,只需简单地#include pqxx / pqxx,因此我建立了一个小型项目来完成该工作。 I receive the error: 我收到错误:

fatal error C1083: Cannot open include file: 'pqxx/pqxx': No such file or directory 严重错误C1083:无法打开包含文件:'pqxx / pqxx':没有此类文件或目录

When attempting to build the project. 尝试构建项目时。 I have also tried this will both debug and release builds, to no avail. 我也尝试过将调试和发布版本都无效。

Here is a screenshot of my linker settings. 这是我的链接器设置的屏幕截图

Does anyone have any suggestions for how I might be able to link and use this library from Visual Studio 2015? 是否有人对我如何能够从Visual Studio 2015链接和使用此库提出任何建议?

As Sami Kuhmonen pointed out, this was not actually a linker error, but a compiler error. 正如Sami Kuhmonen指出的那样,这实际上不是链接器错误,而是编译器错误。 I needed to include an actual header, which Visual Studio needed to be able to find. 我需要包含一个实际的标头,Visual Studio需要该标头。 After adding the correct folder (C:\\libpqxx\\include in my case) to Visual Studio's "additional include directories" setting under C\\C++ -> General per drescherjm's suggestion, the program compiles just fine. 将正确的文件夹(在我的情况下为C:\\ libpqxx \\ include)添加到Visual Studio的“其他包含目录”设置下(在c \\ C ++->常规下,按照drescherjm的建议),程序可以正常编译。

For future reference: I did also run into unresolved external linker errors after solving the initial issue. 供将来参考:解决最初的问题后,我也确实遇到了未解决的外部链接器错误。 This is because you need to make sure to also link to ws2_32.lib and libpq.lib. 这是因为您需要确保还链接到ws2_32.lib和libpq.lib。 You also need to copy some other DLL files that libpq also relies on into your libpqxx lib folder. 您还需要将libpq也依赖的其他一些DLL文件复制到libpqxx lib文件夹中。 On my system, I believe these were ssleay32.dll, libeay32.dll, and libintl-8.dll. 在我的系统上,我相信它们是ssleay32.dll,libeay32.dll和libintl-8.dll。 These files reside under the root of the PostgreSQL install. 这些文件位于PostgreSQL安装的根目录下。 The DLL step is mentioned under libpqxx's INSTALL.txt file, however I believe it stated that the DLLs resided one folder under where I actually found them. 在libpqxx的INSTALL.txt文件下提到了DLL步骤,但是我认为它表明DLL驻留在我实际找到它们的位置下的一个文件夹中。

I have also faced same issue. 我也面临同样的问题。 Then I realized that I was building ,my application as a 32bit. 然后我意识到我正在将我的应用程序构建为32位。 I changed the target to x64 and it compiled successfully 我将目标更改为x64并成功编译

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM