C++ Shared libs

C++ Shared libs

Post by hemani » Wed, 15 Apr 1998 04:00:00



After creating shared libs from C++ sources, I find that the
names of classes, methods are mangled (different) from their
original names. I cannot use dlsym to locate these objects because
they have embedded chars in them. (eg., Factory becomes "__FHFactoryv")
How can one generate shared libs such that the symbols are preserved as
they are ?

This is on solaris 2.5, sparcstation 10.
compiled using : CC -pic -G -o <shared_lib.so> foo.cc -lC

Please post replies to the newsgroup.

Thanks,
-RSN

 
 
 

C++ Shared libs

Post by Casper H.S. Dik - Network Security Engine » Wed, 15 Apr 1998 04:00:00


[[ PLEASE DON'T SEND ME EMAIL COPIES OF POSTINGS ]]


>After creating shared libs from C++ sources, I find that the
>names of classes, methods are mangled (different) from their
>original names. I cannot use dlsym to locate these objects because
>they have embedded chars in them. (eg., Factory becomes "__FHFactoryv")
>How can one generate shared libs such that the symbols are preserved as
>they are ?

By defining them as "extern C" functions.

Casper
--
Expressed in this posting are my opinions.  They are in no way related
to opinions held by my employer, Sun Microsystems.
Statements on Sun products included here are not gospel and may
be fiction rather than truth.

 
 
 

C++ Shared libs

Post by hemani » Wed, 15 Apr 1998 04:00:00



> [[ PLEASE DON'T SEND ME EMAIL COPIES OF POSTINGS ]]


> >After creating shared libs from C++ sources, I find that the
> >names of classes, methods are mangled (different) from their
> >original names. I cannot use dlsym to locate these objects because
> >they have embedded chars in them. (eg., Factory becomes "__FHFactoryv")
> >How can one generate shared libs such that the symbols are preserved as
> >they are ?

> By defining them as "extern C" functions.

Doesn't work. Can you elaborate ?

Thanks,
-RSN

 
 
 

C++ Shared libs

Post by nebo » Wed, 15 Apr 1998 04:00:00



> After creating shared libs from C++ sources, I find that the
> names of classes, methods are mangled (different) from their
> original names. I cannot use dlsym to locate these objects because
> they have embedded chars in them. (eg., Factory becomes "__FHFactoryv")
> How can one generate shared libs such that the symbols are preserved as
> they are ?

> This is on solaris 2.5, sparcstation 10.
> compiled using : CC -pic -G -o <shared_lib.so> foo.cc -lC

> Please post replies to the newsgroup.

> Thanks,
> -RSN

        Many compilers use name mangling to keep overloaded functions apart.
        there should be a command line argument to turn off name mangling, but be
        sure you don't have any overloaded functions, or 1: you'll get an error
        2: the compiler will choose the first function definition it comes across
        and ignore any others after that.

--

                Nb


 
 
 

C++ Shared libs

Post by Casper H.S. Dik - Network Security Engine » Wed, 15 Apr 1998 04:00:00


[[ PLEASE DON'T SEND ME EMAIL COPIES OF POSTINGS ]]


>> >After creating shared libs from C++ sources, I find that the
>> >names of classes, methods are mangled (different) from their
>> >original names. I cannot use dlsym to locate these objects because
>> >they have embedded chars in them. (eg., Factory becomes "__FHFactoryv")
>> >How can one generate shared libs such that the symbols are preserved as
>> >they are ?

>> By defining them as "extern C" functions.

>Doesn't work. Can you elaborate ?

Well, C++ has overloading yet the linker doesn't so the C++ compiler needs
to do somethign special to make overloading work.  Hence is uses
mangling.  This makes all the functions with the same name (but with different
arguments/results) unique to the linker.

Now, if you don't want mangling, i.e., the ability to use dlsym(),
you need to surround the declaration of such funstions with:

extern "C" {

Quote:}

and namemangling will be off; however, the function cannot be a member
function and it can no longer be overloaded as well.

Casper

--
Expressed in this posting are my opinions.  They are in no way related
to opinions held by my employer, Sun Microsystems.
Statements on Sun products included here are not gospel and may
be fiction rather than truth.

 
 
 

1. Problem creating C++ shared libs on AIX

Please forgive me if this has been asked before, but this is my
first visit to this newsgroup.

I'm trying to build a simple shared library using C++ under IBM's
AIX 4.2.1 on an RS 6000 machine and have been unsuccessful so far.

The examples on pages 19-20 of Kevin E. Leininger's "AIX 6000
Developer's Took Kit" book have been the basis for my first
effort.  I can successfully build the C example in the book
but am having problems building a C++ shared library.

The source code of the library (common.C) and header (common.h) looks
like this:

int common();

#include <iostream.h>
#include "common.h"
int common()
{
   cout << "This is a shared library function\n";
   return 0;

It was successfully compiled with the command:

xlC -c common.C -o common.o

The export file, common.exp, looks like this:

#! ./commonobj
common

The link command looks like this:

ld -H512 -T512 -bglink:/lib/glink.o -b export:common.exp -bM:SRE -ocommonobj -lC common.o

The result of this operation is the following error message:

ld: 0711-327 WARNING: Entry point not found: __start
ld: 0711-319 WARNING: Exported symbol not defined: common
ld: 0711-244 ERROR: No csects or exported symbols have been saved.

Can anyone tell what the problem might be?

THANKS IN ADVANCE!

Martin Sagara

2. XFree86 , Digital LK46W-A2 keyboard, Emacs, JED & HELP PLEASE

3. HPUX 9.05 C++ shared libs question, more detail

4. Are There Third-Party Drives for IBM Disk Drive Arrays?

5. Compatibility: HP C++ shared libs and g++ ???

6. snoop + ssh ?

7. Help - shared libs lib****.so.4 lib***.so.5

8. ftp.freebsd.org is toast! :-(

9. Aix4.3 C++ and shared libs problem

10. C++ exceptions inside shared libs

11. Shared libs, C++, static constructor considerations

12. C++ exceptions in shared libs

13. !! shared C++ lib , HELP please !!