Use libpq ++ in Ubuntu 14.04
The c ++ interface of ipvs has long been changed to libpqxx. libpq ++ cannot be compiled in Ubuntu 14.04. Some modifications are required to use libpq ++.
Download libpq1_0000-4.0.tar.gz and decompress it.
------------------------------------------ Split line ------------------------------------------
Free in http://linux.bkjia.com/
The username and password are both www.bkjia.com
The specific download directory uses libpq ++/
For the download method, see
------------------------------------------ Split line ------------------------------------------
2. Go to the libpq ++-4.0 directory
3. Open Makefile
Modify POSTGRES_HOME =/opt/PostgreSQL/9.3 (your postgresql installation directory)
Modify CXXOPTS =-fPIC-DHAVE_NAMESPACE_STD-DHAVE_CXX_STRING_HEADER-DDLLIMPORT = ""
-FPIC must be added to 64-bit Systems
4. Open pgdatabase. cc
Include the stdlib. h file name at the beginning (otherwise the atoi function cannot be found)
V. make & sudo make install
6. Add/etc/ld. so. conf. d/or LD_LIBRARY_PATH to the library search path.
Run sudo ldconfig-v
Or add-Wl,-rpath =/opt/PostgreSQL/9.3/lib during compilation.
VII. Test
Test. cpp (modify mydb and mytable)
# Include <stdlib. h>
# Include <iostream>
# Include <libpq ++. h>
Using namespace std;
Int main (){
Char query_string [256] = "SELECT * FROM mytable ;";
PgDatabase data ("dbname = mydb ");
If (data. ConnectionBad ()){
Cout <"connected failed" <endl;
Cout <"Error is" <data. ErrorMessage () <endl;
Exit (1 );
}
If (! Data. ExecTuplesOk (query_string )){
Cout <"Query Failed! "<Endl;
Exit (1 );
}
For (int k = 0; k
Cout <data. FieldName (k );
Cout <"";
}
Cout <endl;
For (int I = 0; I <data. Tuples (); I ++ ){
For (int k = 0; k
Cout <data. GetValue (I, k );
Cout <"| ";
}
Cout <endl;
}
Return 0;
}
G ++ test. cpp-o test-fPIC-DHAVE_NAMESPACE_STD-DHAVE_CXX_STRING_HEADER-DDLLIMPORT = ""-I/opt/PostgreSQL/9.3/include-L/opt/PostgreSQL/9.3/lib-lpq ++- lpq
./Test