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

Creating a shared library in AIX

371 views
Skip to first unread message

Raman Chalotra

unread,
Mar 23, 2009, 11:47:27 PM3/23/09
to
Hi All,

I have two queries

a)

I am creating a shared library on AIX 5.1 machine using gcc 4.0.0 with
following command:
gcc -shared -o libTEST.so a.o b.o c.o

I am getting following error:
----------------------------------------------------------------------------------------------------------------------------------------------------------
ld: 0711-317 ERROR: Undefined symbol: .pthread_self
ld: 0711-317 ERROR: Undefined symbol: .pthread_mutex_trylock
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
make: 1254-004 The error code from the last command is 1.
----------------------------------------------------------------------------------------------------------------------------------------------------------
All the object files are compiled using -fPIC flag and some of these
files make reference to pthread APIs.

I understand that this error can be avoided by providing -lpthread
option in above command line. However, I am just not confident about
this thing on AIX. Is this safe to do so on AIX?

b) I have some legacy code that builds a library with following
command

1) ld -G -bnogc -o libTEST2.so obj1.o obj2.o obj3.o

Though the libraray builds succesfully, but I am unable to link any
app to this library. e.g.

----------------------------------------------------------------------------------------------------------------------------------------------------------
2)
gcc -Wl,-brtl -L. demo.o -lTEST2 -o demo
ld: 0711-317 ERROR: Undefined symbol: .MyFunc
ld: 0711-345 Use the -bloadmap or -bnoquiet option to obtain more
information.
collect2: ld returned 8 exit status
make: 1254-004 The error code from the last command is 1.
----------------------------------------------------------------------------------------------------------------------------------------------------------
If I change the command 1 as "gcc -shared -o libTEST2.so obj1.o
obj2.o obj3.o" then command 2 succeeds.

Now, I am unable to understand why this library was build with "ld"
command instead of "gcc". Also, I am not sure of the behavior of -
bnogc flag. what is the garbage collector in AIX?


Any help on this shall be highly appreciated.

Thanks,
Raman


Gary R. Hook

unread,
Mar 24, 2009, 9:27:32 AM3/24/09
to
Raman Chalotra wrote:
>
> I am creating a shared library on AIX 5.1 machine using gcc 4.0.0 with
> following command:
> gcc -shared -o libTEST.so a.o b.o c.o
>
> I am getting following error:
> ----------------------------------------------------------------------------------------------------------------------------------------------------------
> ld: 0711-317 ERROR: Undefined symbol: .pthread_self
> ld: 0711-317 ERROR: Undefined symbol: .pthread_mutex_trylock
> 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
> make: 1254-004 The error code from the last command is 1.
> ----------------------------------------------------------------------------------------------------------------------------------------------------------
> All the object files are compiled using -fPIC flag and some of these
> files make reference to pthread APIs.
>
> I understand that this error can be avoided by providing -lpthread
> option in above command line. However, I am just not confident about
> this thing on AIX. Is this safe to do so on AIX?

Um, interesting comment; wish I understood it. However, you don't have
a choice.

On AIX you should always reference any dependent libraries at link time.
This is primarily because an archive will often contain both shared and
static modules, the latter of which you can only incorporate when
linking. Building threaded code? Add -lpthreads.

> b) I have some legacy code that builds a library with following
> command
>
> 1) ld -G -bnogc -o libTEST2.so obj1.o obj2.o obj3.o
>
> Though the libraray builds succesfully, but I am unable to link any
> app to this library. e.g.

That's because you haven't exported any symbols. Add -bexpfull.

> Now, I am unable to understand why this library was build with "ld"
> command instead of "gcc". Also, I am not sure of the behavior of -
> bnogc flag. what is the garbage collector in AIX?

YOu need to do some reading on how shared modules work on AIX.
Try googling for "Gary Hook linking" to find some of my documents.


--
Gary R. Hook
________________________________________________________________________
Vocatus atque non vocatus deus aderit

monster

unread,
Mar 26, 2009, 1:55:23 AM3/26/09
to
gcc -shared -o libTEST.so a.o b.o c.o -lpthread -lxti


0 new messages