아래의 예제프로그램을 컴파일 해보았는데 에러가뜨네요..
분명이 헤더파일은 /usr/include/pgsql/libpq/fe.h 에
있는데 말이에요... 도와주세요..
에러내용은 다음과 같아요...
db3.c: In function `main':
db3.c:37: warning: assignment makes pointer from integer without a cast
/tmp/ccXf6woP.o: In function `exit_nicely':
/tmp/ccXf6woP.o(.text+0x8): undefined reference to `PQfinish'
/tmp/ccXf6woP.o: In function `main':
/tmp/ccXf6woP.o(.text+0x6f): undefined reference to `PQsetdbLogin'
/tmp/ccXf6woP.o(.text+0x80): undefined reference to `PQstatus'
/tmp/ccXf6woP.o(.text+0xaa): undefined reference to `PQerrorMessage'
/tmp/ccXf6woP.o(.text+0xdd): undefined reference to `PQexec'
/tmp/ccXf6woP.o(.text+0xf4): undefined reference to `PQresultStatus'
/tmp/ccXf6woP.o(.text+0x11c): undefined reference to `PQclear'
/tmp/ccXf6woP.o(.text+0x134): undefined reference to `PQclear'
/tmp/ccXf6woP.o(.text+0x153): undefined reference to `PQconsumeInput'
/tmp/ccXf6woP.o(.text+0x165): undefined reference to `PQnotifies'
/tmp/ccXf6woP.o(.text+0x1b7): undefined reference to `PQfinish'
collect2: ld returned 1 exit status
////////////////////////////////////////////////////////////////////////////
#include <stdio.h>
#include "pgsql/libpq/fe.h"
void
exit_nicely(PGconn *conn)
{
PQfinish(conn);
exit(1);
}
main()
{
char *pghost,
*pgport,
*pgoptions,
*pgtty;
char *dbName;
int nFields;
int i,
j;
PGconn *conn;
PGresult *res;
PGnotify *notify;
/*
* begin, by setting the parameters for a backend connection if the
* parameters are null, then the system will try to use reasonable
* defaults by looking up environment variables or, failing that,
* using hardwired constants
*/
pghost = NULL; /* host name of the backend server */
pgport = NULL; /* port of the backend server */
pgoptions = NULL; /* special options to start up the backend
* server */
pgtty = NULL; /* debugging tty for the backend server */
dbName = getenv("USER"); /* change this to the name of your test
* database */
/* make a connection to the database */
conn = PQsetdb(pghost, pgport, pgoptions, pgtty, dbName);
/*
* check to see that the backend connection was successfully made
*/
if (PQstatus(conn) == CONNECTION_BAD)
{
fprintf(stderr, "Connection to database '%s' failed.\n", dbName);
fprintf(stderr, "%s", PQerrorMessage(conn));
exit_nicely(conn);
}
res = PQexec(conn, "LISTEN TBL2");
if (!res || PQresultStatus(res) != PGRES_COMMAND_OK)
{
fprintf(stderr, "LISTEN command failed\n");
PQclear(res);
exit_nicely(conn);
}
/*
* should PQclear PGresult whenever it is no longer needed to avoid
* memory leaks
*/
PQclear(res);
while (1)
{
/*
* wait a little bit between checks; waiting with select()
* would be more efficient.
*/
sleep(1);
/* collect any asynchronous backend messages */
PQconsumeInput(conn);
/* check for asynchronous notify messages */
while ((notify = PQnotifies(conn)) != NULL)
{
fprintf(stderr,
"ASYNC NOTIFY of '%s' from backend pid '%d' received\n",
notify/>relname, notify/>be_pid);
free(notify);
}
}
/* close the connection to the database and cleanup */
PQfinish(conn);
}
|