how can i compile shared library using gcc?

how can i compile shared library using gcc?

Post by Lee Sukch » Wed, 14 Jun 2000 04:00:00



i can't compile aix shared object.

this is my test
$g++ test.o -o test.so -shared

but, error occured.
ld: 0711-317 ERROR: Undefined symbol: .pthread_mutex_init
ld: 0711-317 ERROR: Undefined symbol: .pthread_mutex_lock
ld: 0711-317 ERROR: Undefined symbol: .pthread_mutex_unlock
ld: 0711-345 Use the -bloadmap or -bnoquiet option to obtain more
information.
collect2: ld returned 8 exit status

because, pthread was not exported.

Of course,
$g++ test.o -o test.so -shared -lpthread
this is well doing.

but, i don't want to contain pthread in my shared object.
how can i export pthread in my shared object(do not contain).

 
 
 

how can i compile shared library using gcc?

Post by Lee Sukch » Wed, 14 Jun 2000 04:00:00


i can't compile aix shared object.

this is my test
$g++ test.o -o test.so -shared

but, error occured.
ld: 0711-317 ERROR: Undefined symbol: .pthread_mutex_init
ld: 0711-317 ERROR: Undefined symbol: .pthread_mutex_lock
ld: 0711-317 ERROR: Undefined symbol: .pthread_mutex_unlock
ld: 0711-345 Use the -bloadmap or -bnoquiet option to obtain more
information.
collect2: ld returned 8 exit status

because, pthread was not exported.

Of course,
$g++ test.o -o test.so -shared -lpthread
this is well doing.

but, i don't want to contain pthread in my shared object.
how can i export pthread in my shared object(do not contain).

 
 
 

how can i compile shared library using gcc?

Post by David Edelsoh » Thu, 15 Jun 2000 04:00:00


Quote:>>>>> Lee Sukchan writes:

Lee> i can't compile aix shared object.
Lee> this is my test
Lee> $g++ test.o -o test.so -shared

Lee> but, error occured.
Lee> ld: 0711-317 ERROR: Undefined symbol: .pthread_mutex_init
Lee> ld: 0711-317 ERROR: Undefined symbol: .pthread_mutex_lock
Lee> ld: 0711-317 ERROR: Undefined symbol: .pthread_mutex_unlock
Lee> ld: 0711-345 Use the -bloadmap or -bnoquiet option to obtain more
Lee> information.
Lee> collect2: ld returned 8 exit status

Lee> because, pthread was not exported.

Lee> Of course,
Lee> $g++ test.o -o test.so -shared -lpthread
Lee> this is well doing.

Lee> but, i don't want to contain pthread in my shared object.
Lee> how can i export pthread in my shared object(do not contain).

        Is this actually linking pthread into your object?  I would have
expected that it created a dependency on the libpthread.a shared library
for test.so.

        If you have problems with non-exported symbols and do not /
cannot export symbols manually with -bE (-Wl,-bE:file.exp from GCC), then
you can use -bexpall (-Wl,-bexpall from GCC) to export all symbols.

        Additionally, if you require System V shared library semantics,
you may need to link the shared object for runtime symbolic linking.  To
do this add -G (-Wl,-G for GCC) to the commandline creating the shared
library and -brtl (-Wl,-brtl for GCC) to the commandline linking the
executable.

David
--
===============================================================================
David Edelsohn                                      T.J. Watson Research Center

+1 914 945 4364 (TL 862)                            Yorktown Heights, NY 10598

 
 
 

how can i compile shared library using gcc?

Post by AJ Webe » Tue, 20 Jun 2000 04:00:00


Why don't you define the functions and types that you're using as
"extern" and the dynamic linker should resolve these at runtime?

Also, I'd recommend explicitly telling the compiler to create Position
Independent Code (-fpic), otherwise runtime linking becomes hit-or-miss
with different executables.

--AJ


> i can't compile aix shared object.

> this is my test
> $g++ test.o -o test.so -shared

> but, error occured.
> ld: 0711-317 ERROR: Undefined symbol: .pthread_mutex_init
> ld: 0711-317 ERROR: Undefined symbol: .pthread_mutex_lock
> ld: 0711-317 ERROR: Undefined symbol: .pthread_mutex_unlock
> ld: 0711-345 Use the -bloadmap or -bnoquiet option to obtain more
> information.
> collect2: ld returned 8 exit status

> because, pthread was not exported.

> Of course,
> $g++ test.o -o test.so -shared -lpthread
> this is well doing.

> but, i don't want to contain pthread in my shared object.
> how can i export pthread in my shared object(do not contain).

 
 
 

how can i compile shared library using gcc?

Post by Gary R. Hoo » Tue, 20 Jun 2000 04:00:00



> Why don't you define the functions and types that you're using as
> "extern" and the dynamic linker should resolve these at runtime?

> Also, I'd recommend explicitly telling the compiler to create Position
> Independent Code (-fpic), otherwise runtime linking becomes hit-or-miss
> with different executables.

Um, an AIX-relevant response would be, reference the pthreads library
when you link (-lpthreads).  AIX uses a different technique for runtime
linking, and _all_ code is PIC.  The above statement applies to other
implementations of *nix.

FWIW, even if RTL is involved, the module containing the definitions
of these symbols would have to be available, and if they're in a
different unreferenced location, they'll never be found.


> > i can't compile aix shared object.

> > this is my test
> > $g++ test.o -o test.so -shared

> > but, error occured.
> > ld: 0711-317 ERROR: Undefined symbol: .pthread_mutex_init
> > ld: 0711-317 ERROR: Undefined symbol: .pthread_mutex_lock
> > ld: 0711-317 ERROR: Undefined symbol: .pthread_mutex_unlock
> > ld: 0711-345 Use the -bloadmap or -bnoquiet option to obtain more
> > information.
> > collect2: ld returned 8 exit status

> > because, pthread was not exported.

No, because pthreads weren't _imported_.

Quote:> > Of course,
> > $g++ test.o -o test.so -shared -lpthread
> > this is well doing.

> > but, i don't want to contain pthread in my shared object.
> > how can i export pthread in my shared object(do not contain).

The pthreads library is a dynamically loaded module.  Simply using
-lpthreads should be adequate to create a reference, which you
can confirm via the "dump -Hv" command on test.so.  The above
command line looks fine.

--
Gary R. Hook / AIX Kernel Development, IBM / These opinions are _MINE_
________________________________________________________________________
A piece of canvas is only the beginning
It takes on character with every loving stroke
This thing of beauty is the passion of an artist's heart
By God's design, we are a skin kaleidoscope    "Colored people", dc Talk

 
 
 

how can i compile shared library using gcc?

Post by AJ Webe » Tue, 20 Jun 2000 04:00:00


Sorry for my naievty.  I've been writing for HPUX and Solaris, and am a bit
new to AIX development...I've been using gcc for a while, though.

But my question to your response:  AIX doesn't have a LD_LIBRARY_PATH or
similar env-variable for library search path?  Does this mean that EVERY AIX
box has to have the libraries installed in the exact same place or they won't
be found?  Maybe my question should be: where can I read-up on the dynamic
loader?

--AJ



> > Why don't you define the functions and types that you're using as
> > "extern" and the dynamic linker should resolve these at runtime?

> > Also, I'd recommend explicitly telling the compiler to create Position
> > Independent Code (-fpic), otherwise runtime linking becomes hit-or-miss
> > with different executables.

> Um, an AIX-relevant response would be, reference the pthreads library
> when you link (-lpthreads).  AIX uses a different technique for runtime
> linking, and _all_ code is PIC.  The above statement applies to other
> implementations of *nix.

> FWIW, even if RTL is involved, the module containing the definitions
> of these symbols would have to be available, and if they're in a
> different unreferenced location, they'll never be found.


> > > i can't compile aix shared object.

> > > this is my test
> > > $g++ test.o -o test.so -shared

> > > but, error occured.
> > > ld: 0711-317 ERROR: Undefined symbol: .pthread_mutex_init
> > > ld: 0711-317 ERROR: Undefined symbol: .pthread_mutex_lock
> > > ld: 0711-317 ERROR: Undefined symbol: .pthread_mutex_unlock
> > > ld: 0711-345 Use the -bloadmap or -bnoquiet option to obtain more
> > > information.
> > > collect2: ld returned 8 exit status

> > > because, pthread was not exported.

> No, because pthreads weren't _imported_.

> > > Of course,
> > > $g++ test.o -o test.so -shared -lpthread
> > > this is well doing.

> > > but, i don't want to contain pthread in my shared object.
> > > how can i export pthread in my shared object(do not contain).

> The pthreads library is a dynamically loaded module.  Simply using
> -lpthreads should be adequate to create a reference, which you
> can confirm via the "dump -Hv" command on test.so.  The above
> command line looks fine.

> --
> Gary R. Hook / AIX Kernel Development, IBM / These opinions are _MINE_
> ________________________________________________________________________
> A piece of canvas is only the beginning
> It takes on character with every loving stroke
> This thing of beauty is the passion of an artist's heart
> By God's design, we are a skin kaleidoscope    "Colored people", dc Talk

 
 
 

how can i compile shared library using gcc?

Post by Gary R. Hoo » Wed, 21 Jun 2000 04:00:00



> Sorry for my naievty.  I've been writing for HPUX and Solaris, and am a bit
> new to AIX development...I've been using gcc for a while, though.

> But my question to your response:  AIX doesn't have a LD_LIBRARY_PATH or
> similar env-variable for library search path?  Does this mean that EVERY AIX
> box has to have the libraries installed in the exact same place or they won't
> be found?  Maybe my question should be: where can I read-up on the dynamic
> loader?

The pubs section on the ld command is your primary reference point.  It
is rather
lengthy and contains a lot of useful information, as well as links to
other
articles of import.  If your pubs aren't installed (all html format,
BTW),
get them installed.  I don't know how anyone functions without them.

AIX uses LIBPATH.  The env. var. will be used by the linker if you don't
use a -L option, so we discourage people from using it.  We consider it
a runtime thing, not a linking thing.

Gary

--
Gary R. Hook / AIX Kernel Development, IBM / These opinions are _MINE_
________________________________________________________________________
A piece of canvas is only the beginning
It takes on character with every loving stroke
This thing of beauty is the passion of an artist's heart
By God's design, we are a skin kaleidoscope    "Colored people", dc Talk

 
 
 

1. Duplicate symbol warnings when compiling shared library using gcc

I've been writing code for a shared libray and think that i have
it working.  I am using the gnu compiler on AIX 4.3.  When linking
the objects I get the following warnings:

ld: 0711-224 WARNING: Duplicate symbol: ._GLOBAL__DI
ld: 0711-224 WARNING: Duplicate symbol: ._GLOBAL__DD
ld: 0711-224 WARNING: Duplicate symbol: _GLOBAL__DI
ld: 0711-224 WARNING: Duplicate symbol: _GLOBAL__DD
ld: 0711-345 Use the -bloadmap or -bnoquiet option to obtain more information.

How can i clean up this problem?

I complile the code into objects with the following code:

$>gcc -DUNIX -fPIC -Wall -g -c xyz.cpp -o xyz.o -I../include

I link the ojbects like this:

$>gcc -DUNIX -fPIC -Wall -shared -Wl,-G,-bnoentry,-bexpall -o xyz.so xyz.o \
-lABC -L../lib -I../include

I thought that perhaps writing an export file might clean this stuff up. But
wasn't sure how to go about exporting methods from a C++ object.

Thanks,
Mark

2. rebuild partition/ftape problems

3. hard compiling shared library with gcc

4. Scanner program?

5. Shared libraries and GNU GCC using gas and gnu ld.

6. Sony 4x CDROM almost works!!

7. Using gcc for building shared libraries

8. Cisco vpnclient 4.8.00 on x86_64 FC5: Failed to establish a VPN connection

9. shared library compilation using gcc

10. Static/Shared Library linking using Linux gcc

11. Creating a shared library using gcc on Solaris?

12. Linking a GCC-compiled library using Sun Workshop

13. Using a library compiled with gcc ...