Difficulty getting started with Postgres C++ interface

Поиск
Список
Период
Сортировка
Искать

Difficulty getting started with Postgres C++ interface

От:
"David Wright" <dwright@mergetel.com>
Дата:
Hi there,

I have been successfully using the perl DBI interface for some time and
have just begun a new project which needs to be written in C++. My
problem is that I am unable to compile even a simple C++ program without
error.

I am running a Mandrake 8.1 distribution of Linux, Postgres version 7.1.2
(with the libpq++ stuff that came with it) and trying to compile with
g++.

my program is:

#include 
#include "libpq++.h"

int main()
{// Open the connection to the database and make sure it is OKconst char* dbName="dbname=dwright";PgDatabase data("dbName");
/*	if ( data.ConnectionBad() ) {	cout << "Connection was unsuccessful..." << endl;	cout << "Error message returned: " << data.ErrorMessage() << endl;return 1;}else	cout << "Connection successful... Enter queries below:" << endl;
// Interactively obtain and execute queriesExecStatusType status;string buf;int done = 0;while (!done){	cout << "> ";	cout.flush();	getline(cin, buf);	if ( buf != "" )		if ( (status = data.Exec( buf.c_str() ))				== PGRES_TUPLES_OK )			data.DisplayTuples();		else			cout << "No tuples returned..." << endl				<< "status = " << status << endl				<< "Error returned: "				<< data.ErrorMessage() << endl;	else		done = 1;} */return 0;
} // End main()

Note that I have commented out everything except the connect!!

my command line is:

g++ -I/usr/include/pgsql myc.cpp -o myc

and the error messages are:

/home/dwright/tmp/ccx7SvXE.o: In function `PgDatabase::PgDatabase(char const *)':
/home/dwright/tmp/ccx7SvXE.o(.PgDatabase::gnu.linkonce.t.(char const *)+0x13): undefined reference to `PgConnection::PgConnection(char const *)'
/home/dwright/tmp/ccx7SvXE.o: In function `PgDatabase::~PgDatabase(void)':
/home/dwright/tmp/ccx7SvXE.o(.gnu.linkonce.t._._10PgDatabase+0x1d): undefined reference to `PgConnection::~PgConnection(void)'
/home/dwright/tmp/ccx7SvXE.o: In function `PgDatabase type_info function':
/home/dwright/tmp/ccx7SvXE.o(.gnu.linkonce.t.__tf10PgDatabase+0x10): undefined reference to `PgConnection type_info function'
/home/dwright/tmp/ccx7SvXE.o(.gnu.linkonce.t.__tf10PgDatabase+0x18): undefined reference to `PgConnection type_info node'
collect2: ld returned 1 exit status

Any assistance will be greatly appreciated.

Regards,
David
-- 
David Wright
912 - 614 Lake Street
St. Catharines, ON  L2N 6P6
Web Site: 

Re: Difficulty getting started with Postgres C++ interface

От:
"Jeroen T. Vermeulen" <jtv@xs4all.nl>
Дата:
On Mon, Jan 27, 2003 at 05:42:11PM -0500, David Wright wrote:
> 
> g++ -I/usr/include/pgsql myc.cpp -o myc
> 
> /home/dwright/tmp/ccx7SvXE.o(.PgDatabase::gnu.linkonce.t.(char const *)+0x13): undefined reference to `PgConnection::PgConnection(char const *)'

If you're going to use a library, you'll have to link to it to get
a working program:

g++ -I/usr/include/pgsql myc.cpp -lpq++ -o myc

You may also have to link to the underlying C library, libpq:

g++ -I/usr/include/pgsql myc.cpp -lpq++ -lpq -o myc



And finally--shameless plug coming up--you may want to use libpqxx
instead of libpq++:
 http://gborg.postgresql.org/project/libpqxx/


Jeroen


FAQ