Operating System - HP-UX
1756287 Members
2540 Online
108844 Solutions
New Discussion

Problem linking with a shared library that uses static library

 
Walid Fouad
New Member

Problem linking with a shared library that uses static library

I'm trying to compile an application with the following configuration
1. static library lib1.a that contains a function fun1().
2. static library lib2.a that contains a function fun2() that uses fun1() from lib1.a
3. shared library libshared.so that contains a function funshared() that uses fun2() from lib2.a
4. executable that uses libshared.so
5. I compile the static and shared libraries sources as well as the executable sources with these flags: aCC -c +O3 -w -AA +DD64 -DHP_UX -D_USE_BIG_FDS -mt
6. I create the static with these flags: ar cr
7. I create the shared library with these flags: aCC -b libshared.so -llib1.a -llib2.a
8. I create the executable with these flags: aCC +O3 -w -AA +DD64 -DHP_UX -D_USE_BIG_FDS -mt libshared.so
The problem is that i get this error ld: (Warning) Unsatisfied symbol "func1()" while creating the executable. The problem is solved when i include both lib1.a and lib2.a in the linking of the executable like this: aCC +O3 -w -AA +DD64 -DHP_UX -D_USE_BIG_FDS -mt libshared.so -llib1.a -llib2.a
but i think i don't have to include the static libraries in the linking as i already did when building the shared library. Is there any other way i can resolve this warning.
1 REPLY 1
Dennis Handly
Acclaimed Contributor

Re: Problem linking with a shared library that uses static library

>1. static library lib1.a that contains a function fun1().

(A terminology note: These are archive libs, not static.)

>3. shared library libshared.so that contains a function funshared() that uses fun2() from lib2.a
>7. I create the shared library with these flags: aCC -b libshared.so -llib1.a -llib2.a

Are fun2 and fun1 in libshared.so?

>aCC -c +O3 -w -AA +DD64

I would suggest you leave off +O3 until you get things working. Also never use -w, instead add +W#### to suppress individual warnings.

>I think I don't have to include the static libraries in the linking as I already did when building the shared library.

Check to see if you have those functions in your shlib:
elfdump -n .dynsym -s libshared.so |
grep -e fun1 -e fun2

Make sure these symbols are mangled to match the symbol in your warning. And are being exported.

If not in your shlib, you need to force them there.