2017-02-20 11 views
0

Недавно был запущен проект, над которым я работаю, для того чтобы добавить поддержку postgresql. Проект написан на C (его открытый источник Janus gateway).undefined ссылка на `PQconnectdb '

Я просил эти шаги установить 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 я получаю:

[email protected] ~/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-кодом?

Спасибо!

EDIT: Забыл упомянуть, я запускаю это на виртуальной машине Linux Mint (основная машина - программа macbook pro).

+0

ли Makefile в том же каталоге, что и '#include" ./connect.h "'? Возможно нет. Возможно, вам нужно изменить '#include" ./connect.h "' на правильный путь. Или измените каталоги '-I'. –

+0

@FiddlingBits Оба 'connect.c' и' connect.h' находятся в одном каталоге, называемом db. – IvRRimUm

+0

@FiddlingBits Как я могу изменить каталоги -I? Где это делать и как? – IvRRimUm

ответ

1

Выяснил это.

приложена -L/.... -psql в AM_CFLAGS Makefile.am

Heres полная линия:

AM_CFLAGS += -fstack-protector-all -g -ggdb -fPIC -rdynamic -pthread -L/usr/include/postgresql/libpq -lpq 

Вы можете проверить Янус шлюз Makefile.am, чтобы увидеть, как мой Makefile.am выглядит без -psql