zoukankan      html  css  js  c++  java
  • linux下postgresql的c程序编译问题

    linux下c程序使用postgresql 8.4连接数据库时编译出现的问题。

    1.

    问题:In function `main':

    `PGconn' undeclared (first use in this function)

    `PGresult' undeclared (first use in this function)

    `CONNECTION_BAD' undeclared (first use in this function)

    `PGRES_COMMAND_OK' undeclared (first use in this function)

    `PGRES_TUPLES_OK' undeclared (first use in this function)

     

    出现此问题,为缺少#include <libpq-fe.h>

    2.

    问题:libpq-fe.h: No such file or directory
    解决:系统未查找到libpq-fe.h,需要指定其目录
    方式1:gcc -c -I/usr/local/pgsql/include test.c
    方式2:Makefile文件中,CPPFLAGS += -I/usr/local/pgsql/include

    3.编译.c至.o通过,但链接时出现如下问题
    In function `main':
    undefined reference to `PQsetdbLogin'
    undefined reference to `PQstatus'
    undefined reference to `PQerrorMessage'
    解决:此为缺少链接所需的库文件导致,需手动指定其目录
    gcc -o test test1.o test2.o -L/usr/local/pgsql/lib -lpq

    编译成功。

    参考:http://www.postgresql.org/docs/8.4/interactive/libpq-build.html

     总结:更多详细至官方搜索解决方案,google时多使用site:来限定搜索范围,更快速找到问题解决方法。

  • 相关阅读:
    Xcode代码块快捷输入
    Git常用命令
    vim
    MACOX中apache配置
    IOS中实现动画的几种方式
    Swift与OC混合编译
    网络图像加载
    我对互联网的理解
    运行时
    自动布局使用
  • 原文地址:https://www.cnblogs.com/xfiver/p/2355642.html
Copyright © 2011-2022 走看看