Https://www.2cto.com/database/201707/658910.html
Development environment
Visual Studio 2017[15.2 (26430.16)]
PostgreSQL 9.6.3
Configuration steps
Download the required version of PostgreSQL from the above URL first. There are 32-bit and 64-bit options here, where the number of digits refers to the number of bits of software you have called PostgreSQL to develop, not your computer.
Open the downloaded installation package, most of the steps can be directly clicked "Next".
In the "Password" interface you can add a password to the default user (username "prostgres").
When the installation is complete, remove the hook and click "Finish".
Create a new project, this article selects the console Application (empty project) for easy demonstration.
Enter the project properties.
Select the corresponding platform configuration, the configuration needs to be configured separately.
Add the "include" folder under the PostgreSQL installation directory to your project.
method, add the "Lib" folder to the project.
Add Libpq.lib.
Manually enter "Libpq.lib".
Complete the project configuration.
Open the PostgreSQL installation directory.
Copy the "Libeay32.dll", "Libiconv-2.dll", "Libintl-8.dll", "Ssleay32.dll" in the "Lib" folder to the project directory.
Copy "Libpq.dll" from the "Bin" folder to the project directory.
Test code
Do not forget to select the project platform configuration before testing the code
int lib_ver = PQlibVersion();
printf("Version of libpq: %d\n", lib_ver);
PGconn *conn = PQconnectdb("host=192.168.1.104 dbname=testdb user=postgres password=abc123");//The bank should be modified according to personal circumstances if (PQstatus(conn) == CONNECTION_BAD) {
fprintf(stderr, "Connection to database failed: %s\n",
PQerrorMessage(conn));
PQfinish(conn);
return 0;
}
int ver = PQserverVersion(conn);
printf("Server version: %d\n", ver);
PQfinish(conn);
return 0;
Operation Result:
VisualStudio (VS2017) configuration c/c++-postgresql (9.6.3) Development environment (ZT)