开发者

Why do I get compilation errors when trying to connect to postgresql with c?

I tried to create a simple c programm which should connect to my postgres db, but I am not able to get aware of the following compilation errors... I am using Ubuntu (but also tried to compile on Fedora already - with the same errors...)

uname --all
Linux alp2nwmon001 2.6.35-25-server #44-Ubuntu SMP Fri Jan 21 19:09:14 UTC 2011 x86_64 GNU/Linux

I installed postgres inclusive libpq-dev libpq5 libs already and I have no clue why this simple code is not working...

#include "/usr/include/postgresql/libpq-fe.h"

int main () {
        PGConn *test;
        return 0;
}

I also tried lots of variations like: #include <libpq-fe.h>, and specify the path to the .h file when calling gcc. But always the same errors...

gcc -c -I/usr/include/postgresql/ -L/usr/lib/ -lpq pqtest.c -o postgres
 pqtest.c: In function main:
 pqtest.c:4: error: PGConn undeclared (first use in this function)
 pqtest.c:4: error: (Each undeclared identifier is reported only once
 pqtest.c:4: error: for each function it appears in.)
 pqtest.c:4: error: test undeclared (first use in this function)

Furt开发者_C百科her I found a lot of howtos, but still the same result:

  • http://www.mkyong.com/database/how-to-building-postgresql-libpq-programs/
  • http://forum.ubuntu-fr.org/viewtopic.php?pid=3212499

I also checked the API description at the postgres webpage, still no luck.

In my opinion all files exist where the should exist...

ls -lah /usr/include/postgresql/libpq-fe.h 
-rw-r--r-- 1 root root 20K 2011-04-20 16:36 /usr/include/postgresql/libpq-fe.h

And the libraries...

ls /usr/lib/ | grep pq
libpq.a
libpq.so
libpq.so.5
libpq.so.5.2
libpqxx-2.6.9.so
libpqxx.la
libpqxx.so

I hope somebody can help me here... Thx br, roegi


Use PGconn instead of PGConn.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜