Postgresql connectors using VC++

☆樱花仙子☆ 提交于 2021-01-24 11:19:54

问题


How to add Libpqxx library in visual c++ .I googled it from past 2 days not able to get solution for the same

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


回答1:


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.

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.

Step 1

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 and youtube are great places to get an understating of CMake, another resource:

https://cmake.org/cmake/help/latest/guide/tutorial/index.html

Alternatively, you can install libpqxx through vcpkg but at the time of writing only version 6.4 is available.

Step 2

Follow the instructions here to build the libpqxx library:

https://github.com/jtv/libpqxx/blob/master/INSTALL-Windows.md

Pay special attention to the author who recommends building libpqxx as a static library for windows.

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.

Step 3

I assume you have a project ready in VC++2019. Do this:

Project Properties -> VC ++ Directories -> Include Directories -> (insert include path for the libpqxx source files)

Project Properties -> VC ++ Directories -> Library Directories -> (insert include path for both pqxx.lib and libpq.lib files)

Project Properties -> C/C ++ -> Additional Include Directories -> (insert include path for libpqxx source files)

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)

The Ws2_32.lib file can be the silent assassin for the uninitiated in this whole equation.

Step 4

I assume you have a table set up in PostgreSQL. Go here to test:

https://libpqxx.readthedocs.io/en/7.0.7/a01329.html



来源:https://stackoverflow.com/questions/60111660/postgresql-connectors-using-vc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!