Thread: link problems when inheriting from libpq++

link problems when inheriting from libpq++

From
"Chris Holman"
Date:
I have recently used the libpq++.a library as it stands to carry out SELECT
and INSERT command with few problems.
Its a pleasure to use, my compliments to you all. However...

I would now like to inherit the PgCursor class into one of my own classes.
Seems easy enough, but I have come up against a problem with the linker.

If I try to compile the code below with a simple makefile, the linker
(collect2) complains it cannot find the constructor for PgCursor. This is
true if I try to inherit from any of the classes in the libpq++.a library.
The linker output is shown below.

What am I doing wrong? If I comment out the declaration of 'newPgCursor
causesLinkErrors', then the code builds and works perfectly!

Are there link options I need to consider if I want to inherit from the
library?
I have tried building my own libraries and inheriting from them, using a
similar make file, but they work fine.

This has kept me going round in circles for a good few days now.
I would REALLY appreciate some suggestions, I seem to be getting nowhere!

Regards,
Chris Holman

******************** CODE STARTS **************************
#include "libpq++.H"

class newPgCursor: public PgCursor{
public:  newPgCursor():PgCursor("dbname=testing", "cdh2"){}
};

void main(void){  /***********  why does next line cause problems during
link?*************/  newPgCursor causesLinkErrors;  PgCursor cdh("dbname=testing", "cdh1");
  if(cdh.ConnectionBad()){ cout << "bad connection" << endl; exit(1);}
  if (!cdh.ExecCommandOk("insert into person (e_firstname) values ('a
Name');")){      cout << "couldnt insert persons name" << endl;  }
  cout << "check the program ran" << endl;
} 
******************** CODE ENDS **************************

******************** MAKEFILE STARTS **************************
CCC=g++

GCCOPTIONS= -frtti -D_CPPRTTI 

PGSQLDIR= /usr/include/pgsql
PGDIR= $(PGSQLDIR)/libpq
PGPLUSDIR=$(PGSQLDIR)/libpq++
PGLIBDIR= /usr/lib

INCLUDEPATH=  -I$(PGDIR) -I$(PGPLUSDIR) -I$(PGSQLDIR)

COMPILEDIRECTIVE= $(GCCOPTIONS) $(DEBUGOPTIONS) $(INCLUDEPATH)

LINKDIRECTIVE= -L$(PGLIBDIR)

TEST_APP= test.exe
bitstest: test.o $(CCC) -o $(TEST_APP) test.o $(LINKDIRECTIVE) -lpq++ -lpqchmod 777 $(TEST_APP)

clean:rm -f *.o

.SUFFIXES: .cpp .C .cc .cxx .o

%.o: %.cpp$(CCC) $(COMPILEDIRECTIVE) -c $< -o $@ 
******************** MAKEFILE ENDS **************************


******************** LINKER OUTPUT STARTS **************************
[chrish@pigpen testString]$ make
g++ -frtti -D_CPPRTTI -D_UNIT_TEST_OBJECT_   -I/usr/include/pgsql/libpq -I/usr/i
nclude/pgsql/libpq++ -I/usr/include/pgsql -c test.cpp -o test.o
g++ -o test.exe test.o -L/usr/lib -lpq++ -lpq
test.o: In function `newPgCursor type_info function':
test.o(.gnu.linkonce.t.__tf11newPgCursor+0xd): undefined reference to `PgCursor
type_info function'
test.o(.gnu.linkonce.t.__tf11newPgCursor+0x14): undefined reference to `PgCursortype_info node'
collect2: ld returned 1 exit status
make: *** [bitstest] Error 1
******************** LINKER OUTPUT ENDS **************************

Regards,
Chris Holman





Re: [INTERFACES] link problems when inheriting from libpq++

From
Guido Goldstein
Date:
Hi!

On Thu, 17 Feb 2000 12:21:47 -0000 "Chris Holman" <chrish@owl.co.uk> wrote:
[...]
> void main(void){
>    /***********  why does next line cause problems during
> link?*************/
>    newPgCursor causesLinkErrors;
>    PgCursor cdh("dbname=testing", "cdh1");
[...]
> CCC=g++
> 
> GCCOPTIONS= -frtti -D_CPPRTTI              ^^^^^^^
Viewpoint 1

[...]
> ******************** LINKER OUTPUT STARTS **************************
> [chrish@pigpen testString]$ make
> g++ -frtti -D_CPPRTTI -D_UNIT_TEST_OBJECT_   -I/usr/include/pgsql/libpq -I/usr/i
> nclude/pgsql/libpq++ -I/usr/include/pgsql -c test.cpp -o test.o
> g++ -o test.exe test.o -L/usr/lib -lpq++ -lpq
> test.o: In function `newPgCursor type_info function':
> test.o(.gnu.linkonce.t.__tf11newPgCursor+0xd): undefined reference to `PgCursor
> type_info function'

Read the error message!

You're compiling your program with RTTI (runtime-type-information)
enabled (see Viepoint 1). Before you can use other C++-Libs you have
to make sure that these libs also include the RTTI code.

HIH Guido
-- 
The biggest improvement in performance is the non-working-to-working
transition.                                           -- John Ousterhout


RE: [INTERFACES] link problems when inheriting from libpq++

From
"Chris Holman"
Date:
Thanks for the insightful observation Guido! VERY VERY much apreciated.

I will admit, I have not come across rtti until now. Hence why the error
meant nothing to me. Ahh well, back to the books.
The '-frtti' compile flag was copied from a makefile of another library I am
using.
The GCC manual has no reference to this flag! I can only assume that it is
the default?
If I replace it with '-fno-rtti' the example builds perfectly. I cant wait
to see how the other library reacts to this change.;-)

many thanks,
Chris Holman