首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >对“`PQconnectdb”的未定义引用

对“`PQconnectdb”的未定义引用
EN

Stack Overflow用户
提问于 2017-02-20 16:20:56
回答 1查看 3K关注 0票数 1

最近,我正在处理一个项目,请求向其添加postgresql支持。项目是用C(它的开源Janus网关)编写的。

我按照下面的步骤安装后置和libps-dev。

代码语言:javascript
复制
sudo apt-get install postgresql
sudo apt-get install libpq-dev
$ sudo -u postgres psql postgres
psql (9.3.9)
Type "help" for help.

postgres=# \password postgres

然后在我的头(connect.h)文件中:

代码语言:javascript
复制
#include <postgresql/libpq-fe.h>
#include "debug.h"

/*! \brief Connect to postgresql database
 * If successfull, returns PGconn type
 * If not exits the program
 * @param[in] postgres connection params, ex. username, db, host, etc.
 */
PGconn *connect_to_database(gchar connection_params);

/*! \brief Closes connection to database
 * @param[in] PGconn instance
 */
PGconn *close_connection_to_database(PGconn *pgconn);

以及我的.c(connect.c)文件:

代码语言:javascript
复制
/*! \file    db.c
 * \author   ...
 * \copyright GNU General Public License v3
 * \brief    Event handler notifications (headers)
 * \details  This file contains methods for safely creating databse connection
 * to postgresql and then closing it.
 * 
 * \ingroup db
 * \ref db
 */

#include "./connect.h"

PGconn *connect_to_database(gchar connection_params) {
  JANUS_LOG(LOG_WARN, "TESTINGSSS \n\n\n\n");


  const char test_connect = "testings";

  PGconn *conn = PQconnectdb(test_connect);

  return conn;
}

make上我得到:

代码语言:javascript
复制
todns@todnnns-VirtualBox ~/Projects/janus-gateway $ make
make  all-recursive
make[1]: Entering directory '/home/todns/Projects/janus-gateway'
Making all in html
make[2]: Entering directory '/home/todns/Projects/janus-gateway/html'
make[2]: Nothing to be done for 'all'.
make[2]: Leaving directory '/home/todns/Projects/janus-gateway/html'
make[2]: Entering directory '/home/todns/Projects/janus-gateway'
  CCLD     janus
db/janus-connect.o: In function `connect_to_database':
/home/todns/Projects/janus-gateway/db/connect.c:20: undefined reference to `PQconnectdb'
collect2: error: ld returned 1 exit status
Makefile:1195: recipe for target 'janus' failed
make[2]: *** [janus] Error 1
make[2]: Leaving directory '/home/todns/Projects/janus-gateway'
Makefile:1914: recipe for target 'all-recursive' failed
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory '/home/todns/Projects/janus-gateway'
Makefile:905: recipe for target 'all' failed
make: *** [all] Error 2

问题是:

代码语言:javascript
复制
db/janus-connect.o: In function `connect_to_database':
    /home/todns/Projects/janus-gateway/db/connect.c:20: undefined

我的直觉告诉我,这与Makefile.am文件有关,但我真的不知道该改变什么。所以问题是:我在这个设置中遗漏了什么?如何将postgres库与我的C代码链接?

谢谢!

编辑:忘了提到,我是在Linux虚拟机上运行的(主机器是macbook )。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-02-20 17:19:53

弄明白了。

-L/.... -psql附加到AM_CFLAGS Makefile.am

以下是整行内容:

代码语言:javascript
复制
AM_CFLAGS += -fstack-protector-all -g -ggdb -fPIC -rdynamic -pthread -L/usr/include/postgresql/libpq -lpq

您可以查看janus-网关Makefile.am,看看我的Makefile.am在没有-psql的情况下是什么样子。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42349485

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档