Operating System - HP-UX
1752587 Members
4480 Online
108788 Solutions
New Discussion юеВ

Re: Connection to Postgresql from C or C++ program

 
SOLVED
Go to solution
Vinay_19
Occasional Advisor

Connection to Postgresql from C or C++ program

I am trying to connect to a Postgresql database from either C or C++ program.I have a HP-UX 11.23i (Itanium Processor ,64 bit),ia64,rx2600.

I get a compiler error when I compile. I am using libpg-fe.h.Is there a Library Path I am supposed to set and where should it point to.I am using the following program.Is there any other way to connect to databases in C or C++

Error:-

$ cc testpg.c
ld: Unsatisfied symbol "PQconnectdb" in file testpg.o
1 errors.


#include
#include
#include
int main() {
printf( "Hello World");
PGconn *conn;
const char *connection_str= "host=localhost user=postgres password=postgres dbname=mdpdb";
conn= PQconnectdb(connection_str);
/* if (PQstatus(conn) == CONNECTION_BAD ) {
fprintf(stderr,"Connection to %s failed,%s",connection_str,PQerrorMessage(conn));
}
else { printf("Connected OK\n");
}
PQfinish(conn); */
return EXIT_SUCCESS;
}


Help Appreciated
Thank you very much,
Vinay
program is attached.



2 REPLIES 2
Werner Ittner
Occasional Advisor
Solution

Re: Connection to Postgresql from C or C++ program

I connect this way (postgresql to SuSE linux; HPUX is probably very similar) :

a) environment variables :
export LD_RUN_PATH=/usr/local/pgsql/bin
export LD_LIBRARY_PATH=/usr/local/pgsql/lib
export PATH=/usr/loacal/pgsql/bin:$PATH

b) precompile
ecpg prog.pgc

c) compile+link
cc -I/usr/local/pgsql/include -c prog.c
cc -o prog.r prog.o -L/usr/local/pgsql/lib -lecpg

Werner
Vinay_19
Occasional Advisor

Re: Connection to Postgresql from C or C++ program

That worked great on HP-UX too. and also worked great on Suse Linix 7.3

Thank you Werner