Re: Same symbol, two libraries



Frank Cusack <fcusack@xxxxxxxxxxx> writes:

I thought the search order was "this" library first?

Only with -Bsymbolic, which is not the default.

$ cat foo.c
int bar() { printf("bar from %s\n", __FILE__); return 42; }
int foo() { printf("foo from %s\n", __FILE__); return bar(); }

$ cat foo2.c
int bar() { printf("bar from %s\n", __FILE__); return 24; }
int foo2() { printf("foo2 from %s\n", __FILE__); return bar(); }

$ cat main.c
int main() { return foo() + foo2(); }

$ cc -G -o foo.so foo.c && cc -G -o foo2.so foo2.c &&
cc main.c ./foo.so ./foo2.so && ./a.out; echo $?
foo from foo.c
bar from foo.c
foo2 from foo2.c
bar from foo.c
84

$ cc -Bsymbolic -G -o foo2.so foo2.c && ./a.out; echo $?
foo from foo.c
bar from foo.c
foo2 from foo2.c
bar from foo2.c
66

The '-Bsymbolic' is effectively the default on AIX and Win32,
and is one of the things that makes porting between Win32 or AIX
and the rest of UNIXes such a pain.

Cheers,
--
In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.
.



Relevant Pages