Recently work on a project requires querying PostgreSQL database data processing display, need to use in Windows environment, check the relevant data can use LIBPQXX Open Source Library to do database login, query.
Specific database login, query, etc., here do not need to repeat, there is a lot of information on the network, I will not swim, write a thought good tutorial link http://www.tutorialspoint.com/postgresql/postgresql_c_ Cpp.htm, I hope to help you.
The following will enter the focus, LIBPQXX environment of the building. (Refer to other bloggers ' notes http://www.cppblog.com/deajosha/archive/2015/11/07/211146.html)
1. Download PostgreSQL and Libpgxx
postgresql:http://www.postgresql.org/download/Select the PostgreSQL installation package (x86 and x64) under the Windows version.
Libpgxx:https://github.com/dreamsxin/libpqxx (Of course I'm going down here http://pqxx.org/devprojects/libpqxx/doc/stable/html/Reference/)
LIBPGXX website Information Address: http://pqxx.org/devprojects/libpqxx/doc/4.0/html/Reference/
Libpgxx Tutorial Address: http://pqxx.org/devprojects/libpqxx/doc/4.0/html/Tutorial/
2. Installing PostgreSQL
Click Install PostgreSQL installation package. If you want to compile a 32-bit libpgxx, download the 32-bit PostgreSQL installer and install it with one click. However, the latest version of PostgreSQL has a disturbing problem, that is, the installation to the end will pop up stack builder selection problem, in fact, if you do not have a special need to completely choose to cancel here to end. Of course if you need other features you can enter the selection. I just need simple features like database connectivity and queries in the C + + interface under Windows, and that's where it ends.
3. Compiling libpgxx4.0.1
3.1 Unzip the libpqxx4.0.1 compressed package, save Win32\common-sample as Win32\common, open the Win32\common file using the UE compiler,
Modify the value of PGSQLSRC to the root directory of the PostgreSQL installation, such as C:\Program Files (x86) \postgresql\9.5.
Comment out the libpqinc=$ (PGSQLSRC) \INTERFACES\LIBPQ
Cancel
libpqinc=$ (PGSQLSRC) \include's comments.
Put libpqpath=$ (PGSQLSRC) \interfaces\libpq\release
Libpqdll=libpq.dll Libpqlib=libpqdll.lib commented out,
Cancel
libpqdpath=$ (PGSQLSRC) \lib libpqddll=libpq.dll libpqdlib=libpq.lib comment. libpqdpath=$ (PGSQLSRC) \interfaces\libpq\debug Libpqddll=libpqd.dll Libpqdlib=libpqddll.lib commented out,
Cancel
libpqdpath=$ (PGSQLSRC) \lib Libpqddll=libpq.dll libpqdlib=libpq.lib comments.
3.2 Copy all header files under the Config\ample-headers\compile\visualstudio2010\pqxx\ directory to the INCLUDE\PQXX directory;
Copy all header files under the Config\sample-headers\libpq\9.0\pqxx\ directory to the Include\pqxx directory.
3.3 If you are compiling a 64-bit libpqxx, open the Win32\vc-libpqxx.mak file using UE compilation and
Link_flags_base=kernel32.lib ws2_32.lib advapi32.lib/nologo/dll/machine:i386 shell32.lib secur32.lib wldap32.lib
Revision changed to
Link_flags_base=kernel32.lib ws2_32.lib advapi32.lib/nologo/dll/machine:x64 shell32.lib secur32.lib wldap32.lib
3.4 Add # include <algorithm> to the 34 lines of the Src\largeobject.cxx file (otherwise, it will be compiled with an error).
3.5 Select Command Prompt line tool under Visual Studio Tools under Visual Studio 2015 (I use the VS2015 Developer command prompt, and of course you can also use the X86,x64-compatible tool command prompts) and run as Administrator;
To run the command:
"C:\Program Files (x86) \microsoft Visual Studio 12.0\vc\bin\amd64\nmake.exe"/f Win32/vc-libpqxx.mak all.
After the compilation is successful, the debug/release of the compiled output static link library and the Debug/release file of the dynamic link library are placed in the Lib directory such as:
A careful friend may find that I have more than 4 files in my directory Libeay32.dll,libiconv-2.dll,libintl-8.dll,ssleay32.dll. These files in my use Libpqxx write C + + program compile prompt when the lack of dynamic library, this is found on the Internet files, put in this directory just fine.
Finally, there is a problem, that is, when writing C + + code needs to configure the visual solution, specifically add additional header files, additional dependencies are not introduced here. It is necessary to remind libpqxx that it is best to choose the static version. Since the use of the non-static version of the Benbow Master First choice, compile can pass, that is, in the run time to report abnormal, troubled for a long time. According to my speculation should be non-static version of the lack of some system-dependent dynamic library bar, also no longer do the drill, interested friends can use the Depends.exe tool to find the next.
VS2015 Build LIBPQXX Environment