Use libpq ++ in Ubuntu14.04

Source: Internet
Author: User
The c ++ interface of ipvs has long been changed to libpqxx. libpq ++ cannot be compiled and passed in Ubuntu14.04. Some changes need to be made to use libpq ++. Download libpq1_0000-4.0.tar.gz and decompress it ------------------------------------------ split line -------------------------------------------- free on

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 onHttp://linux.linuxidc.com/

Both the user name and password areWww.linuxidc.com

The specific download directory is in/October 14.04/October 13/October 13/Ubuntu use libpq ++/

Download Method see http://www.linuxidc.com/Linux/2013-07/87684.htm

------------------------------------------ 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
# Include
# Include
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" < Exit (1 );
}
If (! Data. ExecTuplesOk (query_string )){
Cout <"Query Failed! "<Endl;
Exit (1 );
}
For (int k = 0; k
Cout < Cout <"";
}
Cout < For (int I = 0; I <data. Tuples (); I ++ ){
For (int k = 0; k
Cout <data. GetValue (I, k );
Cout <"| ";
}
Cout < }
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

For more information about Ubuntu, see Ubuntu special page http://www.linuxidc.com/topicnews.aspx? Tid = 2

This article permanently updates the link address: Http://www.linuxidc.com/Linux/2015-12/126168.htm

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.