Thread: Cant compile using stock RH71 and libpq++
Can anyone please help (before I go insane). In learning C++, QT and PostgreSQL I have created a very simple program to connect to my database but I cannot compile it. I really cannot see what I am doing wrong. Postgress is running and was fully installed when I installed Redhat 7.1. The libpq++ header is truly in the specified path. I can successfully compile and connect using C. Thanks in advance. John Bend. Here is the simple program: #include <iostream> #include <libpq++.h> int main() { PgDatabase db("dbname=template1"); cout << "Program pg1.cpp finished" << endl; } I compile it with the line: g++ pg1.cpp -I/usr/include/pgsql -lpq And get the following error: /tmp/ccqlJ23X.o: In function `PgDatabase::PgDatabase(char const *)': /tmp/ccqlJ23X.o(.PgDatabase::gnu.linkonce.t.(char const *)+0x13): undefined reference to `PgConnection::PgConnection(char const *)' /tmp/ccqlJ23X.o: In function `PgDatabase::~PgDatabase(void)': /tmp/ccqlJ23X.o(.gnu.linkonce.t._._10PgDatabase+0x1d): undefined reference to `PgConnection::~PgConnection(void)' /tmp/ccqlJ23X.o: In function `PgDatabase type_info function': /tmp/ccqlJ23X.o(.gnu.linkonce.t.__tf10PgDatabase+0x10): undefined reference to `PgConnection type_info function' /tmp/ccqlJ23X.o(.gnu.linkonce.t.__tf10PgDatabase+0x18): undefined reference to `PgConnection type_info node' collect2: ld returned 1 exit status
Solved it. My compile line was incorrect. I now use: g++ {sourcfile} -o {runfile} \ -I/usr/include/pgsql \ -L/usr/include/pgsql/lib -lpq++ (Where \ are line continuation characters.) John Bend. bend@ITstuff.net (John Bend) wrote in message news:<1d5dfd51.0108181012.13e0ab15@posting.google.com>... > Can anyone please help (before I go insane). > > In learning C++, QT and PostgreSQL I have created a very simple > program to connect to my database but I cannot compile it. I really > cannot see what I am doing wrong. > > Postgress is running and was fully installed when I installed Redhat > 7.1. The libpq++ header is truly in the specified path. I can > successfully compile and connect using C. > > Thanks in advance. > > John Bend. > > > Here is the simple program: > > #include <iostream> > #include <libpq++.h> > > > int main() > { > > PgDatabase db("dbname=template1"); > > cout << "Program pg1.cpp finished" << endl; > > } > > > I compile it with the line: > > g++ pg1.cpp -I/usr/include/pgsql -lpq > > > And get the following error: > > /tmp/ccqlJ23X.o: In function `PgDatabase::PgDatabase(char const *)': > /tmp/ccqlJ23X.o(.PgDatabase::gnu.linkonce.t.(char const *)+0x13): > undefined reference to `PgConnection::PgConnection(char const *)' > /tmp/ccqlJ23X.o: In function `PgDatabase::~PgDatabase(void)': > /tmp/ccqlJ23X.o(.gnu.linkonce.t._._10PgDatabase+0x1d): undefined > reference to `PgConnection::~PgConnection(void)' > /tmp/ccqlJ23X.o: In function `PgDatabase type_info function': > /tmp/ccqlJ23X.o(.gnu.linkonce.t.__tf10PgDatabase+0x10): undefined > reference to `PgConnection type_info function' > /tmp/ccqlJ23X.o(.gnu.linkonce.t.__tf10PgDatabase+0x18): undefined > reference to `PgConnection type_info node' > collect2: ld returned 1 exit status