LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 782|回复: 2

postgresql入门级问题:编译连接可通过,执行不了,郁闷!!!

[复制链接]
发表于 2005-4-29 22:08:00 | 显示全部楼层 |阅读模式
  1. /*
  2. * dbtest.c
  3. */
  4. #include <stdio.h>
  5. #include <libpq-fe.h>

  6. void
  7. exit_nicely(PGconn *conn)
  8. {
  9.    PQfinish(conn);
  10.    exit(1);
  11. }

  12. main()
  13. {
  14.    char       *pghost,
  15.               *pgport,
  16.               *pgoptions,
  17.               *pgtty;
  18.    char       *dbName;
  19.    int         nFields;
  20.    int         i,
  21.                j;

  22.    /* FILE *debug; */

  23.    PGconn     *conn;
  24.    PGresult   *res;

  25.    /*
  26.     * begin, by setting the parameters for a backend connection if the
  27.     * parameters are null, then the system will try to use reasonable
  28.     * defaults by looking up environment variables or, failing that,
  29.     * using hardwired constants
  30.     */
  31.    pghost = NULL;              /* host name of the backend server */
  32.    pgport = NULL;              /* port of the backend server */
  33.    pgoptions = NULL;           /* special options to start up the backend
  34.                                 * server */
  35.    pgtty = NULL;               /* debugging tty for the backend server */
  36.    dbName = "template1";

  37.    /* make a connection to the database */
  38.    conn = PQsetdb(pghost, pgport, pgoptions, pgtty, dbName);
  39.    if (PQstatus(conn) == CONNECTION_BAD)
  40.    {
  41.        fprintf(stderr, "Connection to database '%s' failed.\n", dbName);
  42.        fprintf(stderr, "%s", PQerrorMessage(conn));
  43.        exit_nicely(conn);
  44.    }
  45.    else
  46.        printf("ok\n");
  47. }
复制代码



然后编译、连接均可通过:
  1. gcc -I/usr/local/pgsql/include/  -c dbtest.c
  2. gcc dbtest.o -o dbtest -L/usr/local/pgsql/lib -lpq
复制代码



当我执行./dbtest的时候,出现如下错误:
  1. error while loading shared libraries: libpq.so.3: cannot open shared object file: No such file or directory
复制代码


如果我把/usr/local/pgsql/lib 下的libpq.so.3复制到dbtest.c所在目录,一切正常,程序正确执行,请问为什么?
发表于 2005-5-1 09:19:59 | 显示全部楼层
郁闷,我COPY下来编译运行没问题。。。。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-5-1 15:01:25 | 显示全部楼层
问题解决,没把pgsql/lib加入LD_LIBRARY_PATH,多谢
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表