pg.ddx.io pgsql-interfaces@postgresql.org mailing list archive
help / color / mirror / Atom feedDifficulty getting started with Postgres C++ interface
2+ messages / 2 participants
[nested] [flat]
* Difficulty getting started with Postgres C++ interface
@ 2003-01-27 22:42 David Wright <dwright@mergetel.com>
2003-01-29 13:13 ` Re: Difficulty getting started with Postgres C++ interface Jeroen T. Vermeulen <jtv@xs4all.nl>
0 siblings, 1 reply; 2+ messages in thread
From: David Wright @ 2003-01-27 22:42 UTC (permalink / raw)
To: pgsql-interfaces
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 <iostream.h>
#include "libpq++.h"
int main()
{
// Open the connection to the database and make sure it is OK
const 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 queries
ExecStatusType 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: <http://www.mergetel.com/~dwright;
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: Difficulty getting started with Postgres C++ interface
2003-01-27 22:42 Difficulty getting started with Postgres C++ interface David Wright <dwright@mergetel.com>
@ 2003-01-29 13:13 ` Jeroen T. Vermeulen <jtv@xs4all.nl>
0 siblings, 0 replies; 2+ messages in thread
From: Jeroen T. Vermeulen @ 2003-01-29 13:13 UTC (permalink / raw)
To: David Wright <dwright@mergetel.com>; +Cc: pgsql-interfaces
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
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2003-01-29 13:13 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-01-27 22:42 Difficulty getting started with Postgres C++ interface David Wright <dwright@mergetel.com>
2003-01-29 13:13 ` Jeroen T. Vermeulen <jtv@xs4all.nl>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox