Compile libpq in Windows

Source: Internet
Author: User

Compile libpq in Windows
During compilation, you must first understand the integrated development environment like VC ide. In fact, nmake is called to compile the project files, it is actually the same as make in Linux. Make calls Cl and other compilation tools during compilation. This is the same as making calls CC and other compilation tools. In simple terms, these compilation methods are exactly the same in Windows and Linux.
The biggest problem I encountered this time was that I could not find the nmake tool and some libraries he called. These libraries were automatically added to the Windows environment variables after the installation of VC IDE, but this time I didn't, so I spent some time doing this.
The entire compilation process is described as follows:

1. Add Windows Environment Variables
A) Added the following in the include variable:
D: \ Program Files \ Microsoft Visual Studio. NET 2003 \ SDK \ V1.1 \ include \; D: \ Program Files \ Microsoft Visual Studio. NET 2003 \ vc7 \ include; D: \ Program Files \ Microsoft Visual Studio. NET 2003 \ vc7 \ platformsdk \ include
B) Added the following in the Lib variable:
D: \ Program Files \ Microsoft Visual Studio. NET 2003 \ SDK \ V1.1 \ Lib \; D: \ Program Files \ Microsoft Visual Studio. NET 2003 \ common7 \ ide; D: \ Program Files \ Microsoft Visual Studio. NET 2003 \ vc7 \ platformsdk \ Lib; D: \ Program Files \ Microsoft Visual Studio. NET 2003 \ vc7 \ Lib
C) Added the following in the PATH variable:
D: \ Program Files \ Microsoft Visual Studio. NET 2003 \ common7 \ ide
Of course, the simplest method is to call the BAT file D: \ Program Files \ Microsoft Visual Studio. NET 2003 \ common7 \ tools \ vsvars32.bat to set environment variables.

2. Start Compilation
CD to enter the {pghome} \ src directory, run the nmake/F win32.mak command, and generate libpq. lib and libpq. dll in the {pghome} \ SRC \ Interfaces \ libpq \ release directory.
PS: {pghome} is the PostgreSQL location.

3. Add a project file
Note that the {pghome} \ SRC \ include and {pghome} \ Interfaces \ libpq directories under the PostgreSQL directory must be added to the project as the include directory,
Otherwise, compilation fails.

4. A simple example
# Include "stdafx. H"
# Include "language. H"
# Include "libpq/libpq-fe.h"

Void verifyccon ()
{
Const char * conninfo;
Pgconn * conn;
Pgresult * res;
Pgnotify * notify;
Int nnotifies;
Conninfo = "host = localhost hostaddr = 127.0.0.1 Port = 5432 dbname = flowrecord user = s Password = NetFlow ";
/* Establish a connection with the database */
Conn = pqconnectdb (conninfo );

/*
* Check whether the connection to the server is established successfully.
*/
If (pqstatus (conn )! = Connection_ OK)
{
STD: cout <"connection to database failed:" <pqerrormessage (conn );
}
Else
{
STD: cout <"connection to database success! "<Endl;
}
}

Int _ tmain (INT argc, _ tchar * argv [])
{
Language L ("Forest ");
Cout <L. getlan () <Endl;
Cnlan CNL ("Forest ");
Cout <CNL. getname () <Endl;

Verifyccon ();

 

return 0;
}

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.