title: Cannot connect to PostgreSQL using C++
body: <p>I am trying to run PostgreSQL on my mac. PostgreQL itself works fine and I can create database and table and stuff but when I try to connect to PostgreSQL using C++ with something like: </p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;/Library/PostgreSQL/8.4/include/libpq-fe.h&gt;
  #include &lt;string&gt;
  
  int     main() {
  PGconn          *conn;
  PGresult        *res;
  int             rec_count;
  
  conn = PQconnectdb("dbname=ljdata host=localhost user=dataman);
  
  if (PQstatus(conn) == CONNECTION_BAD) {
   puts("We were unable to connect to the database");
  exit(0);
  } 
  
  res = PQexec(conn, "update people set phonenumber=\'5055559999\' where id=3");
  </code></pre>
  
  <p>and compile with something like:</p>
  
  <pre><code>g++ -lpq db.cpp -o db
  </code></pre>
  
  <p>I get the error 
      ld: library not found for -lpq</p>
  
  <p>and if I compile without lpq, I get </p>
  
  <pre><code>Undefined symbols:
    "_PQclear", referenced from:
        _main in ccpjNCAU.o
        _main in ccpjNCAU.o"
  </code></pre>
  
  <p>I have already included the libpq-fe.h, shouldn't it work? Does anybody know what went wrong?</p>