Обсуждение: c++ compile/link problem

Поиск
Список
Период
Сортировка

c++ compile/link problem

От
"Shane Hansen"
Дата:
I am struggling trying to get a connection to my postgres database from a c++ program.  I have read the documention and looked at many examples, but when I try to compile the code I get the same type errors every time.  They look like:
 
/tmp/cc38u8Jz.o: In function `main':
/tmp/cc38u8Jz.o(.text+0x3b): undefined reference to `PgConnection::PgConnection(
char const *)'
/tmp/cc38u8Jz.o(.text+0x4e): undefined reference to `PgConnection::~PgConnection
(void)'
collect2: ld returned 1 exit status
 
What am I doing wrong?
 
Shane Hansen

Re: c++ compile/link problem

От
"J. T. Vermeulen"
Дата:
On Thu, 29 Mar 2001, Shane Hansen wrote:

> I am struggling trying to get a connection to my postgres database from a c++ program.  I have read the documention
andlooked at many examples, but when I try to compile the code I get the same type errors every time.  They look like:
 
> 
> /tmp/cc38u8Jz.o: In function `main':
> /tmp/cc38u8Jz.o(.text+0x3b): undefined reference to `PgConnection::PgConnection(
> char const *)'
> /tmp/cc38u8Jz.o(.text+0x4e): undefined reference to `PgConnection::~PgConnection
> (void)'
> collect2: ld returned 1 exit status
> 
> What am I doing wrong?

I'm assuming you've remembered to link to libpq++ here.

This may be a problem with your C++ compiler.  Different compilers, and in some
cases even different versions of the same compiler, mangle C++ identifiers
differently so they won't link to each other's code (and before you ask: yes,
there are good reasons for this--see the C++ FAQ :-).

Have you made sure your version of libpq++ was build with the same compiler?


Jeroen



Re: c++ compile/link problem

От
Randy Jonasz
Дата:
On Thu, 29 Mar 2001, Shane Hansen wrote:

> I am struggling trying to get a connection to my postgres database from a c++ program.  I have read the documention
andlooked at many examples, but when I try to compile the code I get the same type errors every time.  They look like:
 
>
> /tmp/cc38u8Jz.o: In function `main':
> /tmp/cc38u8Jz.o(.text+0x3b): undefined reference to `PgConnection::PgConnection(
> char const *)'
> /tmp/cc38u8Jz.o(.text+0x4e): undefined reference to `PgConnection::~PgConnection
> (void)'
> collect2: ld returned 1 exit status
>
> What am I doing wrong?
>
> Shane Hansen
>

Are you linking youur program with the libpq++ library?  Usually, with g++
I compile programs with
g++ -lpq++ -L /path/to/pgsql/lib -I /path/to/pgsql/include

Hope that helps!

Randy Jonasz
Software Engineer
Click2net Inc.
Web:  http://www.click2net.com
Phone: (905) 271-3550

"You cannot possibly pay a philosopher what he's worth,
but try your best" -- Aristotle