问题描述
如何在 Visual c++ 中添加 Libpqxx 库.我从过去 2 天搜索它无法获得相同的解决方案
How to add Libpqxx library in visual c++ .I googled it from past 2 days not able to get solution for the same
我已经下载并添加了 libpqxx-4.0,但无法在 Visual Studio 中添加,可以为此提供适当的解决方案.提前致谢
I have downloaded and added libpqxx-4.0 but not able to add in visual studio can any give proper solution for this. Thanks in advance
推荐答案
由于这是我的第一个贡献,无论 Raveendra konda 提供的信息有限,我都会花时间回答这个问题.也许它会对 libpqxx 的新手有所帮助.
As it’s my first contribution I will take the time to answer this regardless of the limited information provided by Raveendra konda. Maybe it will be of assistance to someone new to libpqxx.
在撰写本文时,我们使用的是 libpqxx 7.0.7.我将提供一种构建 libpqxx 7.0.7 的解决方案,并假设您使用 Visual C++ 2019 运行 Windows 10.
At the time of writing we are on libpqxx 7.0.7. I will provide one solution to build libpqxx 7.0.7 and assume that you are running Windows 10 with Visual C++ 2019.
第一步
如果您不熟悉 CMake,我建议您立即与它成为朋友.去这里下载并安装 CMake:
If you are unfamiliar with CMake I suggest you become friends with it immediately. Go here and download and install CMake:
https:///github.com/Kitware/CMake/releases/download/v3.17.2/cmake-3.17.2-win64-x64.zip
stackoverflow 和 youtube 是了解 CMake(另一种资源)的好地方:
stackoverflow and youtube are great places to get an understating of CMake, another resource:
https://cmake.org/cmake/help/latest/guide/tutorial/index.html
或者,您可以通过 vcpkg 安装 libpqxx,但在撰写本文时只有 6.4 版可用.
Alternatively, you can install libpqxx through vcpkg but at the time of writing only version 6.4 is available.
第 2 步
按照此处的说明构建 libpqxx 库:
Follow the instructions here to build the libpqxx library:
https://github.com/jtv/libpqxx/blob/master/INSTALL-Windows.md
特别注意推荐将libpqxx构建为windows静态库的作者.
Pay special attention to the author who recommends building libpqxx as a static library for windows.
我假设您已经构建了 libpqxx 库并且可以访问 pqxx.lib、libpq.lib 文件和 libpqxx 源文件.libpq.lib 文件通常位于 PostgreSQL 安装目录中:C:\Program Files\PostgreSQL\12\lib.
I will assume you have built the libpqxx library and have access to pqxx.lib, libpq.lib files and libpqxx source files. The libpq.lib file is located in your PostgreSQL installation directory typically: C:\Program Files\PostgreSQL\12\lib.
步骤 3
我假设您在 VC++2019 中准备了一个项目.这样做:
I assume you have a project ready in VC++2019. Do this:
项目属性 -> VC ++ 目录 -> 包含目录 ->(插入 libpqxx 源文件的包含路径)
Project Properties -> VC ++ Directories -> Include Directories -> (insert include path for the libpqxx source files)
项目属性 -> VC ++ 目录 -> 库目录 ->(插入 pqxx.lib 和 libpq.lib 文件的包含路径)
Project Properties -> VC ++ Directories -> Library Directories -> (insert include path for both pqxx.lib and libpq.lib files)
Project Properties -> C/C++ -> Additional Include Directories ->(插入 libpqxx 源文件的包含路径)
Project Properties -> C/C ++ -> Additional Include Directories -> (insert include path for libpqxx source files)
Project Properties -> Linker -> General ->(插入 pqxx.lib 和 libpq.lib 文件的包含路径)
Project Properties -> Linker -> General -> (insert include path for both pqxx.lib and libpq.lib files)
Project Properties -> Linker -> Input -> (copy and paste -> pqxx.lib libpq.lib Ws2_32.lib)
Project Properties -> Linker -> Input -> (copy and paste -> pqxx.lib libpq.lib Ws2_32.lib)
Ws2_32.lib 文件可以成为整个等式中初学者的无声杀手.
The Ws2_32.lib file can be the silent assassin for the uninitiated in this whole equation.
步骤 4
我假设您在 PostgreSQL 中设置了一个表.去这里测试:
I assume you have a table set up in PostgreSQL. Go here to test:
https://libpqxx.readthedocs.io/en/7.0.7/a01329.html
这篇关于使用 VC++ 的 Postgresql 连接器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!