Operating System - HP-UX
1844185 Members
2485 Online
110229 Solutions
New Discussion

Issue in Loading Shared Object.

 
SOLVED
Go to solution
Saurav Narain
Occasional Contributor

Issue in Loading Shared Object.

Hi All,
I am new to HP Unix and need some help. I created a Shared Object. I have an executable that loads the Shared Object and calls a function from with in the Shared Object. The Shared Object gets loaded and the functon gets called. I know because i am printing some information with in the function.

This works fine till the time the Shared Object and the executable are in the same directory. As soon as i try to load this Shared Object from any other directory dlopen() fails and dlerror() returns " Can't Open Shared Library ".

I have include the SO path in the environment variables LD_LIBRARY_PATH and SHLIB_PATH.

I am compiling the SO as follows

cc +z filename.c this gives me filename.o

/usr/bin/ld -b -lc -lm -o filename.o
This gives me the Shared Object.

Is there any other option that i need to give ?

Thanks and Regards,
Saurav.
3 REPLIES 3
Steven E. Protter
Exalted Contributor
Solution

Re: Issue in Loading Shared Object.

HP-UX needs to have the SHLIB_PATH variable set.

SHLIB_PATH=usr/bin
export SHLIB_PATH

if its already set (check with echo)


SHLIB_PATH=usr/bin:$SHLIB_PATH
export SHLIB_PATH

All set.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Ermin Borovac
Honored Contributor

Re: Issue in Loading Shared Object.

Check your executable (that loads the shared library) with chatr to see if use of SHLIB_PATH is enabled or disabled.

$ /usr/bin/chatr

If you see the following line in the output you can't use SHLIB_PATH to tell your executable where the shared library is.

SHLIB_PATH disabled second

Run the following command to enable use of SHLIB_PATH.

$ /usr/bin/chatr +s enable

If you want SHLIB_PATH to be enabled automatically, compile your executable with -Wl,+s option.

$ cc -Wl,+s test.c -o test
Saurav Narain
Occasional Contributor

Re: Issue in Loading Shared Object.

Thank you.

Regards,
Saurav.