2017-02-20 1 views
0

최근에 내가 postgralsql 지원을 추가하기 위해 requred에서 일하고있는 프로젝트. 프로젝트는 C (오픈 소스 Janus gateway)로 작성됩니다.`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) 파일 : make

/*! \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; 
} 

내가 얻을 :

[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.am 모양을 볼 수 야누스 게이트웨이 Makefile.am을 확인할 수 있습니다

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

'#include "./connect.h"와 같은 디렉토리에 있는가? 아마도 그렇지 않습니다. 어쩌면'#include "./connect.h"를 올바른 경로로 변경해야한다. 또는'-I' 디렉토리를 변경하십시오. –

+0

@FiddlingBits'connect.c'와'connect.h'는 모두 db라는 동일한 디렉토리에 있습니다. – IvRRimUm

+0

@FiddlingBits'-I' 디렉토리를 어떻게 바꿀 수 있습니까? 어떻게하고 어떻게해야합니까? – IvRRimUm

답변

1

알아 냈어.

추가 된 -L/.... -psql Makefile.am AM_CFLAGS

을 Heres 전체 라인 : 당신은 -psql

관련 문제