Compilation and use Libpq under Windows

xiaoxiao2021-03-05  62

These days, because a database connection interface that needs to be designed, the development environment is under Windows, so you must compile libliced ​​lib libraries that libpq's source files can be accessed below. When compiling, the concept that needs to be understood is the integrated development environment like VC IDE. It is actually called the compilation tool such as NMAKE to compile the project file, and the MAKE below Linux is actually the same. Make calls CL and other compilation tools when compiling, this and make calls to CC and other compilation tools are the same, simple to say that these compilation methods are exactly the same below Windows and under Linux. The biggest problem encountered this time is to always find some of the NMAKE tools and some libraries he call. These, in order, it is automatically added to the Windows environment variable after the VC IDE installation is complete, but this time no So I spent some time to get this. The following is the entire compilation process introduction:

1. Add a Windows environment variable to supplement 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 added 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 added inside the PATH variable: D: / Program Files / Microsoft Visual Studio .NET 2003 / Common7 / IDE of course is to call D: / Program Files / Microsoft Visual Studio .NET 2003 / Common7 / Tools / vsvars32. BAT This BAT file is used to set the environment variable.

2, start compiling nmake / f win32.mak)

3, add the project file Note Be sure to add the SRC / INCLUDE below the PostgreSQL directory as the INCLUDE directory, otherwise it is not possible to compile.

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 = postgres password = netflow"; / * And database establishment links * / conn = pqConnectdb (Connifo);

/ * * Check if the connection to the server is successfully established * / 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 cn1); cout << cnl.getname () <

Verifyccon ();

Return 0;}

转载请注明原文地址:https://www.9cbs.com/read-32002.html

New Post(0)