Thread: Problems linking with libpq

Problems linking with libpq

From
Flemming Froekjaer
Date:
I'm trying to compile a small c program that integrates with PostgreSQL,

but when I get to link the prog i get the following error.

/tmp/ccFrRISc.o: In function `main':
/tmp/ccFrRISc.o(.text+0x57): undefined reference to `PQsetdbLogin'

I'm doing this on FreeBSD 4.3 and PostgreSQL is 7.1.2

I made this prog to determine that what causes the problem:

#include </usr/local/include/pgsql/libpq-fe.h>

int main (void) {
  char *pghost,
    *pgport,
    *pgoptions,
    *pgtty,
 *dbUser,
 *dbPassword;
  char *dbName;
  int nFields;
  int i, j;
  PGconn *conn;

  pghost = "localhost";
  pgport = "5432";
  pgoptions = NULL;
  pgtty = NULL;
  dbName = "monitor";
  dbUser = "username";
  dbPassword = "donttell";

  conn = PQsetdbLogin(pghost, pgport, pgoptions, pgtty, dbName, dbUser,
dbPassword);
  return(0);
}

\Flemming


Re: Problems linking with libpq

From
"Oliver Elphick"
Date:
Flemming Froekjaer wrote:
  >I'm trying to compile a small c program that integrates with PostgreSQL,
  >
  >but when I get to link the prog i get the following error.
  >
  >/tmp/ccFrRISc.o: In function `main':
  >/tmp/ccFrRISc.o(.text+0x57): undefined reference to `PQsetdbLogin'

It seems that you aren't in fact linking libpq to your program.

You need something like

  gcc prog.c -L/usr/local/lib/pgsql -lpq

as a minimum.

--
Oliver Elphick                                Oliver.Elphick@lfix.co.uk
Isle of Wight                              http://www.lfix.co.uk/oliver
PGP: 1024R/32B8FAA1: 97 EA 1D 47 72 3F 28 47  6B 7E 39 CC 56 E4 C1 47
GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839  932A 614D 4C34 3E1D 0C1C
                 ========================================
     "But the wisdom that is from above is first pure, then
      peaceable, gentle, and easy to be intreated, full of
      mercy and good fruits, without partiality, and without
      hypocrisy."     James 3:17



Re: Problems linking with libpq

From
missive@frontiernet.net (Lee Harr)
Date:
On Fri, 27 Jul 2001 22:57:36 +0000 (UTC), <flemming@froekjaer.org> wrote:
> I'm trying to compile a small c program that integrates with PostgreSQL,
>
> but when I get to link the prog i get the following error.
>
> /tmp/ccFrRISc.o: In function `main':
> /tmp/ccFrRISc.o(.text+0x57): undefined reference to `PQsetdbLogin'
>
> I'm doing this on FreeBSD 4.3 and PostgreSQL is 7.1.2
>
> I made this prog to determine that what causes the problem:
>
> #include </usr/local/include/pgsql/libpq-fe.h>
>
> int main (void) {
>   char *pghost,
>     *pgport,
>     *pgoptions,
>     *pgtty,
>  *dbUser,
>  *dbPassword;
>   char *dbName;
>   int nFields;
>   int i, j;
>   PGconn *conn;
>
>   pghost = "localhost";
>   pgport = "5432";
>   pgoptions = NULL;
>   pgtty = NULL;
>   dbName = "monitor";
>   dbUser = "username";
>   dbPassword = "donttell";
>
>   conn = PQsetdbLogin(pghost, pgport, pgoptions, pgtty, dbName, dbUser,
> dbPassword);
>   return(0);
> }
>



What is the command line you are using to compile & link your program?