Re: [GENERAL] Problem with compiled C

Поиск
Список
Период
Сортировка
От guy@pop.incentre.net
Тема Re: [GENERAL] Problem with compiled C
Дата
Msg-id 199908122232.QAA10359@bach.incentre.net
обсуждение исходный текст
Список pgsql-general
From: guy@pop.incentre.net
To: pgsql-general-digest@hub.org
Date: Thu, 12 Aug 1999 16:30:34 %z (MDT)
Subject: Re: [GENERAL] Problem with compiled C


..
>   To compile C programs you need to add the pq library, so use something like:
> gcc -o test test.c -lpq
>
> Good luck.
>
> At 04:24 PM 8/11/99, H�ctor Morales wrote:
> >Hi , I have two problems.
> >
> >1. When a use pgacces, i try connect with one database, responde the
> >next error.
> >        Error trying to connect to database "xxxx" on host "xxx"
> >        PostgreSQL error message: Connection to database failed
> >connectDB() --connect() failed: Connection refused Is the postmaster
> >running (whit -i) at "xxx" and accepting connections on TCP/IP por
> >"5432".
> >
..
>So  when I compiled my program in C use
>gcc -o prueba prueba.c  -llibpq.so
>
>responde
>    /usr/bin/ld: cannot open -llibpg.so : no such file or directory
>    collect2: ld returned 1 exit status
>
>I  probe with
>gcc -o prueba prueba.c  -llibpq.so -L/usr/lib
>
>But equal , I sure that the library is in this directory and a observe the
>LD_LIBRARY_PATH and the directory  is in this variable.
>
>So i don't Know why not compiled.
>
>Thanks

Hi

If you have not already tried;

edit /etc/ld.so.conf

 add the location of libpq.so {maybe it is /opt/pgsql/lib}to new line at
 the bottom of the file.

Then run ldconfig, this will reconfigure ld to use the new directory as a
as well as the others in the list for dynamicly linked libraries.

When you specify a library with the CC -lxxx, you do not include the extension
or the "lib" prefix. {use -lpg for libpg.so}

You will also need to include some additional headers

example from "funcs.c" {}:

#include <postgres.h>           /* for char16, etc. */
#include <utils/palloc.h>       /* for palloc */
#include <libpq-fe.h>           /* for TUPPLE, required for most programs */
#include <executor/executor.h>  /* for GetAttributeByName() */

You will need to add an include directory directive on the cc prompt.

example

cc -o test -I/usr/local/pgsql/include -L/usr/local/pgsql/lib -lpg -c test.c

This will compile an executable program {test}, to compile an object file use :

cc -O -I/usr/local/pgsql/include -L/usr/local/pgsql/lib -lpg -c test.c

This will create an object file {test.o}

This should allow the complilation to work, the -L/usr/local/pgsql/lib may not
be nessary, if /etc/ld.so.conf is setup and ldconfig has been run, but I can't
remember for sure.

This is what I use when I write utilities to directly access postgresql.

I have not yet written any C functions, but it should work the same way.

In the source for postgresql there are some examples. The source for funcs.c
is in the source tree, and the procedures in it are documented in the
programmers reference. This file has three or more examples of C functions.

Good Luck



В списке pgsql-general по дате отправления:

Предыдущее
От: "Hub.Org News Admin"
Дата:
Сообщение: ...
Следующее
От: guy@incentre.net
Дата:
Сообщение: Re: [GENERAL] Problem with compiled C