VisualStudio (VS2017) configuration c/c++-postgresql (9.6.3) Development environment (ZT)

Source: Internet
Author: User
Tags postgresql



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)


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.