最近我正在处理的一个项目需要添加postgresql支持。 Project用C语言编写(开源Janus gateway)。
我按照这些步骤安装了postgress和libps-dev。
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)文件中:
#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)文件:
/*! \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
我得到:
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
问题是:
db/janus-connect.o: In function `connect_to_database':
/home/todns/Projects/janus-gateway/db/connect.c:20: undefined
我的直觉告诉我,它与Makefile.am文件有关,但我真的不知道该改变什么。 所以问题是:我在这个设置中缺少什么?如何将postgres-dev库与我的C代码链接?
谢谢!
编辑:忘了提,我在Linux Mint虚拟机上运行它(主机是macbook pro)。
答案 0 :(得分:1)
想出来。
附加 code1 code2 column1
0 B 0 value2
1 C 1 value3
2 C 1 value4
到-L/.... -psql
Makefile.am
全力以赴:
AM_CFLAGS
您可以查看janus-gateway AM_CFLAGS += -fstack-protector-all -g -ggdb -fPIC -rdynamic -pthread -L/usr/include/postgresql/libpq -lpq
,了解我的Makefile.am
在没有Makefile.am
的情况下的外观