Results 1 to 2 of 2
Hi all,
I have a shared library A which uses shared library B, and an application P which relies on A.
I don't want to link P against A and ...
- 07-24-2008 #1Just Joined!
- Join Date
- Jul 2008
- Posts
- 1
gcc link shared library against another shared library
Hi all,
I have a shared library A which uses shared library B, and an application P which relies on A.
I don't want to link P against A and B, but to link P against A only, and A against B.
Thanks for your answers
- 07-24-2008 #2
This will only make a difference if two functions with the same name exist in both libraries, right?
Here ya go.
The output I get:Code:#!/bin/bash cat > a.h <<EOD void fred(void); void barney(void); EOD cat > b.h <<EOD void wilma(void); void barney(void); EOD cat > a1.c <<EOD #include <stdio.h> #include "b.h" void fred(void) { printf("this is fred\n"); wilma(); } EOD cat > a2.c <<EOD #include <stdio.h> #include "b.h" void barney(void) { printf("this is barney from library A\n"); } EOD cat > b1.c <<EOD #include <stdio.h> void wilma(void) { printf("this is wilma\n"); } EOD cat > b2.c <<EOD #include <stdio.h> void barney(void) { printf("this is barney from library B\n"); } EOD cat > main.c <<EOD #include <stdio.h> #include "a.h" int main(void) { fred(); barney(); return 0; } EOD gcc -Wall -c a1.c -o a1.o gcc -Wall -c a2.c -o a2.o gcc -Wall -c b1.c -o b1.o gcc -Wall -c b2.c -o b2.o rm -f a.a b.a # Arrrre you rrrready, mateys? (This script is not pirated from elsewhere.) ar r a.a a1.o ar r a.a a2.o ar r b.a b1.o ar r b.a b2.o # The following ar optional. ar -s a.a ar -s b.a gcc -Wall main.c a.a b.a -o main main
I don't think you can keep library A from linking against itself, but you didn't ask for that. :)Code:this is fred this is wilma this is barney from library A
Hope this helps.--
Bill
Old age and treachery will overcome youth and skill.


Reply With Quote