building & linking with "new style" shared objects

building & linking with "new style" shared objects

Post by Robert Skinne » Sat, 05 May 2001 01:40:27



I'm having problems building a "new style" shared object library and
linking it into an executable using the -l option.  

I must be missing a magic compile or link flag, but I've tried a variety
of options without success.

Any suggestions?

thanks in advance.

AIX 4.3, VisualAge v 5.0.0.0:

% cat sub.C
#include        <stdio.h>

void
sub( int v )
{
    printf( "sub( %d )\n", v );

Quote:}

% CC -G -qmkshrobj -o libsub.so sub.C
% cat main.C
extern void sub( int );

int
main()
{
    sub( 42 );

Quote:}

% CC -c main.C

# this is what I really want, why can't it "find" libsub.so?
% CC -o example main.o -L. -lsub
ld: 0706-006 Cannot find or open library file: -l sub
        ld:open(): A file or directory in the path name does not exist.

# this works, as long as LIBPATH is set
% CC -o example main.o libsub.so
% setenv LIBPATH .
% example
sub( 42 )
% unsetenv LIBPATH

# the -L option works as expected
% CC -o example main.o -L. libsub.so
% example
sub( 42 )

--

Boeing Commercial Airplane Company  Org: 6-6C11, M/S 6F-05
Visualization Applications             Phone: 425.477.4515

 
 
 

building & linking with "new style" shared objects

Post by Dale Talco » Sat, 05 May 2001 01:04:34



>I'm having problems building a "new style" shared object library and
>linking it into an executable using the -l option.  
>I must be missing a magic compile or link flag, but I've tried a variety
>of options without success.
>Any suggestions?

I avoid shared libraries whenever possible, but ...
Does it have to end in ".so"?  If it ends in ".a", it's still dynamically
linked, but ld can find it with the "-L. -lsub" syntax.

--
Dale Talcott, Purdue University Computing Center


 
 
 

building & linking with "new style" shared objects

Post by Gary R. Hoo » Sat, 05 May 2001 22:41:33



> I'm having problems building a "new style" shared object library and
> linking it into an executable using the -l option.

> I must be missing a magic compile or link flag, but I've tried a variety
> of options without success.

From the ld manual page in the pubs:

The -bdynamic option:
"When you specify the rtl option and dynamic mode is in effect,
files ending in .so as well as .a satisfy searches for libraries
specified with the -l (lowercase L) flag. This option only applies
to AIX 4.2 or later. "

and

The -brtl option:
"When dynamic mode is in effect (see the dynamic and static options),
the rtl option allows input files specified with the -l flag to end
in .so as well as in .a."

The AIX paradigm allows multiple shared modules, as well as static
object
files, to exist in a single archive.  Therefore, the historic behavior
has always revolved around a ".a" file.

--
Gary R. Hook / AIX PartnerWorld for Developers / These opinions are MINE
________________________________________________________________________

 
 
 

building & linking with "new style" shared objects

Post by Robert Skinne » Sun, 06 May 2001 00:55:24


thanks, I had read about each flag individually, but missed the AND part
of the language.

--

Boeing Commercial Airplane Company  Org: 6-6C11, M/S 6F-05
Visualization Applications             Phone: 425.477.4515