pg.ddx.io pgsql-interfaces@postgresql.org mailing list archive
help / color / mirror / Atom feedPgConnection
6+ messages / 4 participants
[nested] [flat]
* PgConnection
@ 1998-10-21 19:37 Vasquez, Jason <Jason.Vasquez@Connect.Xerox.com>
0 siblings, 2 replies; 6+ messages in thread
From: Vasquez, Jason @ 1998-10-21 19:37 UTC (permalink / raw)
To: 'pgsql-interfaces@hub.org' <pgsql-interfaces@hub.org>
I have just installed PostgreSQL, and the installation took place with no
problems/errors.
I've read the documentation about using the C++ interface to Postgres, but I
seem to be havin trouble getting anything to compile. Following the example
included with the distribution, I have done something similar to this:
#include <iostream.h>
#include <libpq++.h>
void main() {
PgDatabase data ("foo");
yadayadayada
}
Whenever I do this, I get a compile error stating that there is an undefined
reference to PgConnection. Has anyone had a similar situation, or know how
to remedy this?
Thanks,
-Jason
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: [INTERFACES] PgConnection
@ 1998-10-22 07:33 Joris Esch <joris.esch@esat.kuleuven.ac.be>
parent: Vasquez, Jason <Jason.Vasquez@Connect.Xerox.com>
1 sibling, 0 replies; 6+ messages in thread
From: Joris Esch @ 1998-10-22 07:33 UTC (permalink / raw)
To: Vasquez, Jason <Jason.Vasquez@Connect.Xerox.com>; +Cc: pgsql-interfaces@hub.org
On Wed, 21 Oct 1998, you wrote:
>I have just installed PostgreSQL, and the installation took place with no
>problems/errors.
>
>I've read the documentation about using the C++ interface to Postgres, but I
>seem to be havin trouble getting anything to compile. Following the example
>included with the distribution, I have done something similar to this:
>
>#include <iostream.h>
>#include <libpq++.h>
>
>void main() {
> PgDatabase data ("foo");
>
>yadayadayada
>}
>
>Whenever I do this, I get a compile error stating that there is an undefined
>reference to PgConnection. Has anyone had a similar situation, or know how
>to remedy this?
>
>Thanks,
>-Jason
Hello:
look at the attached code. I hope it's usefull for you.
good luck
joris
--
joris esch, student in electrical engineering
Power is knowledge.
Attachments:
test3.cpp (text/x-c++, 1.8K) download
/* test3.cpp
joris esch 3.10.1998
*/
// compile with:
// c++ test3.cpp -o test3 -lpq -lpq++
#include "test3.h"
void main()
{
bool verbose = true;
char* dbname= "template1";
/* make a connection to the database */
if (verbose) {
cout << "Trying to connect to db " << dbname << '\n';; // << " on host " << pghost;
} ;
// PgDatabase inherits from PgConnection
PgDatabase *conn=new PgDatabase(dbname);
// give error messages if conn is not ok
if (conn->Status()!=0){
cerr << "Connection status: " << conn->Status() <<'\n';
cerr << "Connection failed." << '\n';
cerr << "Database name: " << conn->DBName() << '\n';
cerr << conn->ErrorMessage() << '\n';
//end execution here... or use exception handling...cfr. ch8
exit(1); //Stroustrup page 116 0== okidoki, 1!=okidoki
//throw "Connection failed";
};
if (verbose) {cout << "Connection succeeded.\n";};
cout << "You are currently connected to db: " << conn->DBName() << '\n';
//cout << "Let's do a query";
//see if i can do query...
if (conn->ExecTuplesOk("DECLARE mycursor BINARY CURSOR FOR select * from pg_database")){// 1 means Ok
int no_t=conn->Tuples();
int no_f=conn->Fields();
if (verbose) {
cout << "The number of tuples in the query: " << conn->Tuples() << '\n';
cout << "The number of fields in the query: " << conn->Fields() << '\n';
}
cout << "The query results: \n";
for(int i=0;i < no_t; i++){
for(int j=0;j < no_f; j++){
cout << conn->GetValue(i,j) << '\t';
//cout << conn->GetValue(i,j) << '\n';
}
cout << '\n';
}
} else{
cout << "Execution of query failed\n";//conn
}
//conn->Exec("DECLARE mycursor BINARY CURSOR FOR select * from test");
//return 0;
}
test3.h (text/x-c, 100B) download
/* test3.h
joris esch 3.10.1998
*/
#include <libpq++.h>
#include <iostream>
//typedef int Error;
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: [INTERFACES] PgConnection
@ 1998-10-22 14:58 Tom Lane <tgl@sss.pgh.pa.us>
parent: Vasquez, Jason <Jason.Vasquez@Connect.Xerox.com>
1 sibling, 0 replies; 6+ messages in thread
From: Tom Lane @ 1998-10-22 14:58 UTC (permalink / raw)
To: Vasquez, Jason <Jason.Vasquez@Connect.Xerox.com>; +Cc: pgsql-interfaces@hub.org
"Vasquez, Jason" <Jason.Vasquez@Connect.Xerox.com> writes:
> I've read the documentation about using the C++ interface to Postgres, but I
> seem to be havin trouble getting anything to compile. Following the example
> included with the distribution, I have done something similar to this:
> #include <iostream.h>
> #include <libpq++.h>
> void main() {
> PgDatabase data ("foo");
> yadayadayada
> }
> Whenever I do this, I get a compile error stating that there is an undefined
> reference to PgConnection.
Compile error, or link error? I tried the same, and got complaints
about the linker not being able to find several PgConnection routines
until I added "-L/usr/local/pgsql/lib -lpq++ -lpq" to the command line:
$ g++ -I/usr/local/pgsql/include pgtest.cc
collect2: ld returned 1 exit status
/bin/ld: Unsatisfied symbols:
PgConnection::PgConnection(void)(code)
PgConnection::PgConnection(char const *)(code)
PgConnection::~PgConnection(void)(code)
PQfnumber (code)
$ g++ -I/usr/local/pgsql/include pgtest.cc -L/usr/local/pgsql/lib -lpq++ -lpq
[ no complaint ]
If you're using shared libraries there are also possibilities for
installation problems that prevent libpq++ from finding libpq at run
time, but evidently you're not getting that far yet :-(.
regards, tom lane
^ permalink raw reply [nested|flat] 6+ messages in thread
* RE: [INTERFACES] PgConnection
@ 1998-10-23 11:35 Vasquez, Jason <Jason.Vasquez@Connect.Xerox.com>
0 siblings, 1 reply; 6+ messages in thread
From: Vasquez, Jason @ 1998-10-23 11:35 UTC (permalink / raw)
To: pgsql-interfaces@hub.org
Thanks for your response.
I tried your suggestion, and thing seem to go a little bit better--I still
receive one error at compile time, though. (quite frustrating :) )
Hee's the error I receive:
$> g++ -I/usr/local/pgsql/include mytest.cpp -L/usr/local/pgsql/lib -lpq++
-lpq
/usr/local/pgsql/lib/libpq.a(fe-auth.o): In function 'pg_password_sendauth':
fe-auth.o(.text+0.17): undefined reference to 'crypt'
I even tried making sure that crypt.h was in g++'s search path, but I still
got the same error....
Any ideas?
TIA
-Jason
-----Original Message-----
From: Tom Lane [mailto:tgl@sss.pgh.pa.us]
Sent: Thursday, October 22, 1998 9:58 AM
To: Vasquez, Jason
Cc: pgsql-interfaces@hub.org
Subject: Re: [INTERFACES] PgConnection
"Vasquez, Jason" <Jason.Vasquez@Connect.Xerox.com> writes:
> I've read the documentation about using the C++ interface to Postgres, but
I
> seem to be havin trouble getting anything to compile. Following the
example
> included with the distribution, I have done something similar to this:
> #include <iostream.h>
> #include <libpq++.h>
> void main() {
> PgDatabase data ("foo");
> yadayadayada
> }
> Whenever I do this, I get a compile error stating that there is an
undefined
> reference to PgConnection.
Compile error, or link error? I tried the same, and got complaints
about the linker not being able to find several PgConnection routines
until I added "-L/usr/local/pgsql/lib -lpq++ -lpq" to the command line:
$ g++ -I/usr/local/pgsql/include pgtest.cc
collect2: ld returned 1 exit status
/bin/ld: Unsatisfied symbols:
PgConnection::PgConnection(void)(code)
PgConnection::PgConnection(char const *)(code)
PgConnection::~PgConnection(void)(code)
PQfnumber (code)
$ g++ -I/usr/local/pgsql/include pgtest.cc -L/usr/local/pgsql/lib -lpq++
-lpq
[ no complaint ]
If you're using shared libraries there are also possibilities for
installation problems that prevent libpq++ from finding libpq at run
time, but evidently you're not getting that far yet :-(.
regards, tom lane
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: [INTERFACES] PgConnection
@ 1998-10-23 13:56 Tom Lane <tgl@sss.pgh.pa.us>
parent: Vasquez, Jason <Jason.Vasquez@Connect.Xerox.com>
0 siblings, 0 replies; 6+ messages in thread
From: Tom Lane @ 1998-10-23 13:56 UTC (permalink / raw)
To: Vasquez, Jason <Jason.Vasquez@Connect.Xerox.com>; +Cc: pgsql-interfaces@hub.org
"Vasquez, Jason" <Jason.Vasquez@Connect.Xerox.com> writes:
> Hee's the error I receive:
> $> g++ -I/usr/local/pgsql/include mytest.cpp -L/usr/local/pgsql/lib -lpq++ -lpq
> /usr/local/pgsql/lib/libpq.a(fe-auth.o): In function 'pg_password_sendauth':
> fe-auth.o(.text+0.17): undefined reference to 'crypt'
> I even tried making sure that crypt.h was in g++'s search path, but I still
> got the same error....
This is the same problem as before: you are seeing a link-time error not
a compile-time error. You have to pay attention to whether the library
file can be found as well as whether the header file can be found.
On some machines the crypt functions are not in the standard C library
but in a separate file that you have to write "-lcrypt" to link in.
Perhaps yours is like that.
regards, tom lane
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: [INTERFACES] PgConnection
@ 1998-10-26 14:29 Gus Nwosu <anwosu@houston.geoquest.slb.com>
0 siblings, 0 replies; 6+ messages in thread
From: Gus Nwosu @ 1998-10-26 14:29 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Vasquez, Jason <Jason.Vasquez@Connect.Xerox.com>; pgsql-interfaces@hub.org
At compile time include the line -L/usr/lib -lcrypt while building the failed
objects.
Rgds
Gus
At 09:56 AM 10/23/98 -0400, Tom Lane wrote:
>"Vasquez, Jason" <Jason.Vasquez@Connect.Xerox.com> writes:
>> Hee's the error I receive:
>> $> g++ -I/usr/local/pgsql/include mytest.cpp -L/usr/local/pgsql/lib -lpq++
-lpq
>> /usr/local/pgsql/lib/libpq.a(fe-auth.o): In function
'pg_password_sendauth':
>> fe-auth.o(.text+0.17): undefined reference to 'crypt'
>
>> I even tried making sure that crypt.h was in g++'s search path, but I still
>> got the same error....
>
>This is the same problem as before: you are seeing a link-time error not
>a compile-time error. You have to pay attention to whether the library
>file can be found as well as whether the header file can be found.
>
>On some machines the crypt functions are not in the standard C library
>but in a separate file that you have to write "-lcrypt" to link in.
>Perhaps yours is like that.
>
> regards, tom lane
>
=============================================================
Gus
Nwosu
Tel: 1-(713)350-4301
GeoRise Training Manager
Fax: 1-(713)350-4103
5444 Westheimer Road
Houston. Tx 77056 email:
anwosu@houston.geoquest.slb.com
=============================================================
^ permalink raw reply [nested|flat] 6+ messages in thread
end of thread, other threads:[~1998-10-26 14:29 UTC | newest]
Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
1998-10-21 19:37 PgConnection Vasquez, Jason <Jason.Vasquez@Connect.Xerox.com>
1998-10-22 07:33 ` Joris Esch <joris.esch@esat.kuleuven.ac.be>
1998-10-22 14:58 ` Tom Lane <tgl@sss.pgh.pa.us>
1998-10-23 11:35 RE: [INTERFACES] PgConnection Vasquez, Jason <Jason.Vasquez@Connect.Xerox.com>
1998-10-23 13:56 ` Tom Lane <tgl@sss.pgh.pa.us>
1998-10-26 14:29 Re: [INTERFACES] PgConnection Gus Nwosu <anwosu@houston.geoquest.slb.com>
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