Reputation: 21
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
Upvotes: 2
Views: 2211
Reputation: 31
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 and Visual C++ 2019.
Step 1
If you 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
stackoverlow and youtube are great places to get an understanding 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 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 both 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 both 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
Upvotes: 3
Reputation: 127
I recommend using vcpkg https://vcpkg.io/en/index.html. vcpkg has libpqxx and will install all the dependencies needed for it. It will also link the needed libraries to Visual Studio for you.
Upvotes: 1