4575641 [rkeene@sledge /home/rkeene/tmp/linking-troubles]$ cat log.html
[rkeene@maul linking-troubles]$ grep ^ test.c b.c c1.c c2.c
test.c:#include <stdio.h>
test.c:#include "b.h"
test.c:#include "c2.h"
test.c:
test.c:int main(int argc, char **argv) {
test.c:
test.c:	printf("test.c:main():Calling b()\n");
test.c:	b();
test.c:
test.c:	printf("test.c:main():Calling c()\n");
test.c:	c();
test.c:
test.c:	return(0);
test.c:}
b.c:#include <stdio.h>
b.c:#include "c1.h"
b.c:
b.c:void b(void) {
b.c:	printf("b.c:b():Calling c()\n");
b.c:	c();
b.c:
b.c:	return;
b.c:}
c1.c:#include <stdio.h>
c1.c:#include "c1.h"
c1.c:
c1.c:void c(void) {
c1.c:	printf("c1.c:c():Got here, returning\n");
c1.c:
c1.c:	return;
c1.c:}
c2.c:#include <stdio.h>
c2.c:#include "c2.h"
c2.c:
c2.c:void c(void) {
c2.c:	printf("c2.c:c():Got here, returning\n");
c2.c:
c2.c:	return;
c2.c:}
[rkeene@maul linking-troubles]$ make
gcc -Wall -o "libc1.so" -shared -fPIC c1.c
gcc -Wall -o "libb.so" -shared -fPIC b.c -L. -Wl,-R,. -lc1
gcc -Wall -o "libc2.so" -shared -fPIC c2.c
gcc -Wall -o test test.c -L. -Wl,-R,. -lb -lc2
[rkeene@maul linking-troubles]$ ldd test
        linux-vdso.so.1 (0x00007ffff73fe000)
        libb.so => ./libb.so (0x00007fa182bf3000)
        libc2.so => ./libc2.so (0x00007fa1829f1000)
        libc.so.6 => /lib64/libc.so.6 (0x00007fa18260e000)
        libc1.so => ./libc1.so (0x00007fa18240d000)
        /lib64/ld-linux-x86-64.so.2 (0x00007fa182df5000)
[rkeene@maul linking-troubles]$ ./test
test:Calling b()
b:Calling c()
c2:Got c2
test:Calling c()
c2:Got c2
[rkeene@maul linking-troubles]$
... switch to symbol versioning...
[rkeene@maul linking-troubles]$ make clean
rm -f libb.so libc1.so libc2.so test
[rkeene@maul linking-troubles]$ make
gcc -Wall -o "libc1.so" -shared -fPIC c1.c -Wl,--version-script,c1.ver
gcc -Wall -o "libb.so" -shared -fPIC b.c -L. -Wl,-rpath,. -lc1
gcc -Wall -o "libc2.so" -shared -fPIC c2.c -Wl,--version-script,c2.ver
gcc -Wall -o test test.c -L. -Wl,-R,. -lb -lc2
[rkeene@maul linking-troubles]$ ./test
test:Calling b()
b:Calling c()
c1:Got c1
test:Calling c()
c2:Got c2
[rkeene@maul linking-troubles]$ 
... switch to symbol versioning with --default-symver...
[rkeene@maul linking-troubles]$ make clean
rm -f libb.so libc1.so libc2.so test
[rkeene@maul linking-troubles]$ make
gcc -Wall -o "libc1.so" -shared -fPIC c1.c -Wl,--default-symver
gcc -Wall -o "libb.so" -shared -fPIC b.c -L. -Wl,-rpath,. -lc1
gcc -Wall -o "libc2.so" -shared -fPIC c2.c -Wl,--default-symver
gcc -Wall -o test test.c -L. -Wl,-R,. -lb -lc2
[rkeene@maul linking-troubles]$ ./test
test:Calling b()
b:Calling c()
c1:Got c1
test:Calling c()
c2:Got c2
[rkeene@maul linking-troubles]$ 
4575642 [rkeene@sledge /home/rkeene/tmp/linking-troubles]$

Click here to go back to the directory listing.
Click here to download this file.
last modified: 2016-12-30 22:10:53