Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Loading Dynamic Libraries written in C++ from C with Linux

0 views
Skip to first unread message

Massimiliano Trezzi

unread,
Apr 28, 2001, 9:23:49 AM4/28/01
to
I'm porting an UDF library for Interbase from Win to Linux.
Ad UDF library in Windows it's a DLL with some exported function with as C
functions.
I wrote them with C++ and I exported them using extern "C" keyword, but
Interbase looks them as C functions.
With linux I have a problem accessing the library Interbase does not
recognize it. If I make a C library all it's ok.
I saw that it's a generic problem (not from Interbase) when accesing to
dynamic C++ library from a C program.

I'm using RedHat 7.1 the gcc compiler and the ld linker and now the makefile
is:

# let's call it LA (note: this uses STANDARD C++ LIBRARIES)
INGlobals: INGlobals.o NumUdf.o Stringudf.o
ld -o INGlobals INGlobals.o NumUdf.o Stringudf.o -shared -lgds
INGlobals.o: INGlobals.cpp
g++ -c -fPIC INGlobals.cpp
NumUdf.o: NumUdf.cpp
g++ -c -fPIC NumUdf.cpp
Stringudf.o: StringUdf.cpp
g++ -c -fPIC StringUdf.cpp

I made other two versions of the library:
LB: with C++, but using some simple classes without Standard Libraries.
LC: with pure C (that made with gcc)

I made trhee little programs that access the libraries:
PA: C++ program statically linked to LA
PB: C++ program that uses dl library routines (dlopen(),dlsym(),etc.)
PC: pure C program that uses dl library routines (dlopen(),dlsym(),etc.)

I know that the library exports clear function name by using the nm utility,
bu I have these results:

All it's ok when
PA access to LA
PB access dynamically to LA, LB (i did not try with LC)
PC access dynamically to LC

I get no handle from dlopen() when:
PC access to LA

I get the handle, but I get a "Segmentation Fault" when:
PC tried to use a function exported from LB

I'm sure that when I'l be able to access from PC to LA I'll be able to get
the library wortking as an UDF library on Interbase.

Is there anybody who can help me?

Thank you in advance,
Massimiliano Trezzi


0 new messages