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:
#include <stdio.h>
#include </Library/PostgreSQL/8.4/include/libpq-fe.h>
#include <string>
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");
and compile with something like:
g++ -lpq db.cpp -o db
I get the error ld: library not found for -lpq
and if I compile without lpq, I get
Undefined symbols:
"_PQclear", referenced from:
_main in ccpjNCAU.o
_main in ccpjNCAU.o"
I have already included the libpq-fe.h, shouldn't it work? Does anybody know what went wrong?