Using libpq(c api) and libpqxx(c++ api) to connect postgresql-8.1.3 on WindowsXP
need MinGW Msys postgresql-8.1.3 source baggage
I use libpqxx-2.5.5 look at the libpqxx-2.5.5\win32\Intall.txt
--------------------------------------------------------------------
Getting Started with MinGW and MSYS
(based on contribution by Michael J. Pedersen, 2004-08-17)
MSYS is a Unix-like environment for Windows. Once you have this installed,
building libpqxx should be a lot more like it is under Unix except that the
locations of libraries and such aren't sufficiently standardized.
Packages to download if you don't have them already:
1) MinGW (http://www.mingw.org/), plus any updates.
2) MSYS (http://www.mingw.org/), again with any updates.
3) w32api (http://www.mingw.org/).
4) PostgreSQL (http://www.postgresql.org/).
5) zlib (http://www.zlib.org/).
It is generally recommended to get the latest versions of these packages.
Compiling and installing PostgreSQL before you get to libpqxx:
1) Install MinGW (install to c:\mingw)
2) Install MSYS--but not into MinGW directory tree!
3) Run MSYS (Start->Programs->MinGW->MSYS->msys)
4) Extract, compile, and install zlib
# From main source directory of zlib:
./configure --prefix=c:/mingw/local && make && make install
5) Extract, compile, and install postgres
# From main source directory of PostgreSQL:
./configure --prefix=c:/mingw/local --with-includes=c:/mingw/local/include --with-libs=c:/mingw/local/lib && make && make install
重要:把C:\mingw\local\bin设置环境变量PATH中
6) Extract, compile, and install libpqxx
export LDFLAGS=-lws2_32 && ./configure --prefix=c:/mingw/local --disable-shared --enable-static --disable-thread-safety && make && make install
---------------------------------------------------------------------
Uing it in eclpise cdt
1、设置环境变量PATH C:\mingw\local\lib 使程序能连接到libpq.dll
2、 -I "C:\MinGW\local\include"
-I "C:\MinGW\libpqxx-2.5.5\include"
3、 -l
pqxx
pq
ws2_32
wsock32
注意顺序
-L
"C:\MinGW\local\lib"
"C:\MinGW\lib"
4、测试代码
pqlib C库 \postgresql-8.1.3\src\test\examples
pqlibxx C++ libpqxx-2.5.5\test