2017-02-20 6 views
0

Kürzlich ein Projekt, an dem ich arbeite, benötigt, um postgresql Unterstützung hinzuzufügen. Projekt wird in C geschrieben (seine Open Source Janus gateway).undefined Verweis auf `PQconnectdb '

Ich folge diesen Schritten, um postgress und libps-dev zu installieren.

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 

Da ist in meinem Kopf (connect.h) Datei:

#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); 

Und mein .c (connect.c) file:

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

Auf make i erhalten:

[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 

Das Problem ist:

Mein Darm sagt mir, dass es etwas mit Makefile.am Datei zu tun hat, aber ich weiß nicht wirklich, was ich dort ändern soll. Die Frage ist also: Was fehlt mir in diesem Setup? Wie kann ich die postgres-dev-Bibliothek mit meinem C-Code verbinden?

Danke!

EDIT: Vergessen zu erwähnen, ich bin dies auf Linux Mint virtuelle Maschine laufen (Hauptmaschine ist ein Macbook Pro).

+0

das Makefile im selben Verzeichnis wie '#include" ./connect.h "'? Wahrscheinlich nicht. Vielleicht müssen Sie '#include" ./connect.h "' auf den korrekten Pfad ändern. Oder ändern Sie die "-I" Verzeichnisse. –

+0

@FiddlingBits Sowohl 'connect.c' als auch' connect.h' befinden sich im selben Verzeichnis, db genannt. – IvRRimUm

+0

@FiddlingBits Wie kann ich '-I' Verzeichnisse ändern? Wo und wie? – IvRRimUm

Antwort

1

Ich habe es herausgefunden.

Appended -L/.... -psql-AM_CFLAGS Makefile.am

Heres die durchgezogene Linie:

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

Check-out kann janus Gateway Makefile.am zu sehen, wie mein Makefile.am sieht ohne die -psql