Operating System - HP-UX
1826663 Members
2838 Online
109695 Solutions
New Discussion

Re: Getting error while linking shared library

 
Pravin B
Occasional Contributor

Getting error while linking shared library

Hi

I am using aCC 3.1.5 compiler on HPUX 11.0.
One of my executable DbInit uses Oracle 8.1.5 shared library libclntsh.sl.
It was comipled & linked as follows:

COMPILE : aCC -DDEBUG -ext +W 641,684,829 -z -D_UNIX_ -D__hpux +DAportable -g +objdebug +Z -D_REENTRANT -D_KERNEL_THREADS -D_THREAD_SAFE -I. -I/vobs/hp11/Visigenic/vbroker/include -I/vobs/hp11/Oracle/rdbms/demo -I/vobs/hp11/Oracle/plsql/public -I/vobs/hp11/Oracle/network/public -c DbInit.cpp

LINK : aCC -g -Wl,-B,immediate -Wl,+s -o DbInit DbInit.o -L/vobs/hp11/Oracle/lib -lclntsh -L/vobs/hp11/Visigenic/vbroker/lib -lorb_r -lpthread

The above oracle path is different at the client side.
I am keeping all oracle libraries in /opt/Oracle/lib direcory at the client side. So I am setting SHLIB_PATH & LD_LIBRARY_PATH to that directory. At the client side I don't have /vobs/bldenv/hp11/Oracle/lib directory, When I try to run DbInit executable I am getting following errors.

/usr/lib/dld.sl: Can't open shared library: /vobs/bldenv/hp11/Oracle/lib/libclntsh.sl.8.0
/usr/lib/dld.sl: No such file or directory


Que :
1> For Shared libraries, can I use different LD_LIBRARY_PATH/SHLIB_PATH different from path used while linking?
2> Whether I specified any wrong aCC compilation/Linking option?
3> For above scenario is there any way out.

-Pravin
3 REPLIES 3
Mike Stroyan
Honored Contributor

Re: Getting error while linking shared library

You can change the recorded path for a shared library using the +cdp option of ld. In your current case you would add
+Wl,+cdp,/vobs/bldenv/hp11/Oracle/lib:/opt/Oracle/lib
to replace the link directory with the appropriate runtime directory.
There is another apparent problem with the basename of the library. You linked with -lclntsh but the runtime reference was to libclntsh.sl.8.0. The name with the trailing 8.0 could have come from either an internal name of the library or a symbolic link to a different file. A simple ll of the shared library will show if it is a symbolic link. If you use the chatr command on a shared library it will show if it has an internal name. The internal name can be set by using the ld +h option when creating a shared library. If an internal name is set, it will be remembered instead of the actual file name at link time. If the internal name starts with / it will be used as the full remembered path instead of the actual path at link time.
Mike Stroyan
Honored Contributor

Re: Getting error while linking shared library

Oops, change that "+Wl,+cdp" to "-Wl,+cdp".
Pravin B
Occasional Contributor

Re: Getting error while linking shared library

Hi

Thank you for the reply.
>You can change the recorded path for a shared library using
>the +cdp option of ld. In your current case you would add
>+Wl,+cdp,/vobs/bldenv/hp11/Oracle/lib:/opt/Oracle/lib
>to replace the link directory with the appropriate runtime directory.
But Still I am having problem, Since at the link time
I will not know exactly where I will install oracle product.

>If you use the chatr command on a shared library it
>will show if it has an internal name.
libclntsh.sl.8.0 file is a symbolic link for libclntsh.sl and these both files are in the sam directory.
PROMPT>chatr /vobs/bldenv/hp11/Oracle/lib/libclntsh.sl
/vobs/bldenv/hp11/Oracle/lib/libclntsh.sl:
shared library
shared library dynamic path search:
SHLIB_PATH disabled second
embedded path disabled first Not Defined
internal name:
libclntsh.sl.8.0
shared library list:
dynamic /usr/lib/librt.2
dynamic /usr/lib/libpthread.1
dynamic /usr/lib/libnss_dns.1
dynamic /usr/lib/libdld.2
dynamic /usr/lib/libm.2
dynamic /usr/lib/libc.2
dynamic /usr/lib/libcl.2
shared vtable support disabled
static branch prediction disabled
executable from stack: D (default)
kernel assisted branch prediction enabled
lazy swap allocation disabled
text segment locking disabled
data segment locking disabled
third quadrant private data space disabled
fourth quadrant private data space disabled
data page size: D (default)
instruction page size: D (default)
----------------------------
Que :
1> For Shared libraries, can I use runtime lib path different from link time library path.
2> Whether I specified any wrong aCC compilation/Linking option?
3> At the linking time, I tried using "/vobs/hp11/Oracle/lib/libclntsh.sl" instead of "-L/vobs/hp11/Oracle/lib -lclntsh".
aCC -g -Wl,-B,immediate -Wl,+s -o DbInit DbInit.o /vobs/hp11/Oracle/lib/libclntsh.sl /vobs/hp11/Visigenic/vbroker/lib/liborb_r.sl libpthread.sl
Whether these two ways of linking are same?

-Pravin