General
cancel
Showing results for 
Search instead for 
Did you mean: 

shared libraries - different behaviour in hp-ux and linux

jj458
Advisor

shared libraries - different behaviour in hp-ux and linux

I have a problem with different behaviour of shared libraries in HP-UX and in Linux.

A shared library a.sl contains a module a.c with 2 functions a and b.
Function b is calling some other function c, not contained in the library.

My main program is only calling a, does not need b (and so not c).

On HP-UX 11.11 PA-RISC this is working.
On Linux i get an unresolved symbol c when im am linking main.

Commands on HP-UX:
cc +z -c main.c
cc +z -c a.c
ld -b -o a.sl a.o
cc +z main.o a.sl -o main
./main
hello world

Commands on Linux:
cc -c -o main.o main.c
cc -c -o a.o a.c
ld -shared -o a.so a.o
cc main.o a.so -o main
a.so: undefined reference to `c'

same result on Linux with liba.so:
ld -shared -o liba.so a.o
cc -L. -la main.o -o main
./liba.so: undefined reference to `c'


Im am porting a programs from HP-UX to Linux. Is there a solution for this kind of problem?

I hope im am using the right forum, because this conciders both HP-UX and Linux.

Joachim
Greetings, Joachim
7 REPLIES
Dennis Handly
Acclaimed Contributor

Re: shared libraries - different behaviour in hp-ux and linux

I'll ask the moderators to move this to Linux. This has nothing to do with HP-UX, unless you were porting to Integrity.

If you used the ELF linker you would get a shlib unsat warning.

>Is there a solution for this kind of problem?

Define "c" or provide the shlib that has the definition.
jj458
Advisor

Re: shared libraries - different behaviour in hp-ux and linux

Tnx for the response.
You are right, i am not porting to integrity.

So the only HP-UX part of the question is:

Why do i *not* get an error on HP-UX with this example.

> Define "c" or provide the shlib that has the definition.

This will work in my example. But in real life in the sw i am porting, providing the shlibs leads to other undefined symbols and multiple definitions.

Greetings,
Joachim
Greetings, Joachim
Mike Stroyan
Honored Contributor

Re: shared libraries - different behaviour in hp-ux and linux

You could link with
cc -Wl,--allow-shlib-undefined main.o a.so -o main
on linux.

The 32-bit HP-UX linker defaults to allowing shared libraries to have undefined symbols when linking a program. (The 64-bit HP-UX linker defaults to an error just as linux does and requires +allowunsats.)
Dennis Handly
Acclaimed Contributor

Re: shared libraries - different behaviour in hp-ux and linux

>Why do I *not* get an error on HP-UX with this example?

Because you do, on Integrity. But it's a warning. (Standard is better than better. :-)

>Mike: The 64-bit HP-UX linker defaults to an error just as linux does and requires +allowunsats.

No, if the unsats are in a shlib, it's a warning.
ld: (Warning) Unsatisfied symbol "c" in file liba.so
Goran Koruga
Honored Contributor

Re: shared libraries - different behaviour in hp-ux and linux

Hello.

You can resort to "lazy" linking. From what I can see this is the default on HP-UX.

Regards,
Goran
jj458
Advisor

Re: shared libraries - different behaviour in hp-ux and linux

Tnx to all for your help!

Default on my HP-UX 11.11 64 Bit PA-RISC seems to be lazy linking without warning.

Solution for Linux is:
- Compile with -fpic or -fPIC
- Link with
--allow-shlib-undefined (no warning at link time)
or
--warn-unresolved-symbols

Joachim
Greetings, Joachim
jj458
Advisor

Re: shared libraries - different behaviour in hp-ux and linux

(solution see last post)
Greetings, Joachim