Subject: C compiling problem...

From: Phil Shen <[email-masked]>
Date: Thu, 31 Dec 92 12:02:09 -0800

Hi,

I'm a beginner with the Postgres system, so please bear with me...

I'm running on SunOS ver. 4.1.2.

I've run into a problem with compiling C code into executables to access
Postgres database files.  The problem is, I think I can compile to get .o
files, but not .out* executable files.  I tried to find help in the
reference manual about compiling, but all it says is to use the cc
-IPOSTGRESHOME -IPORTNAME -something about the machine, etc. to compile. 
I have set the environment variables POSTGRESHOME and PORTNAME to
~postgres and sunos4 respectively.

When I try to use "ld" to link the object code, it can't find the
references to PQexe, etc. in the include files.

Can you tell me specifically how to compile the following file on Lillith
to get an executable?  (I realize that the code may not be correct either
but I need to know how to compile the C code first...)

#include <stdio.h>
#include <tmp/libpq-fe.h>
#include <tmp/postgres.h>

main()
{
   int4 Id;

   PQsetdb("db2");
   PQexec("begin");
   printf("\nEnter an id: ");
   scanf("%d",&Id);
   PQexec("retrieve (KBTERMS.name) where (KBTERMS.id =%ld)",Id);
   PQfinish();
 }

Thanks very much for your time,
Phil