# Error while loading shared libraries

**URL:** <https://community.unix.com/t/error-while-loading-shared-libraries/359427>\
**Category:** Programming\
**Created:** [March 28, 2016, 1:08am UTC](https://community.unix.com/t/error-while-loading-shared-libraries/359427 "2016-03-28T01:08:53Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![vdivb](https://community.unix.com/letter_avatar/vdivb/32/5_5575768a8748004e209b776fc1b2916d.png) [@vdivb](https://community.unix.com/u/vdivb)\
**Post date:** [March 28, 2016, 1:08am UTC](https://community.unix.com/t/error-while-loading-shared-libraries/359427/1 "2016-03-28T01:08:53Z")

</div>

I am trying to run a C++ program which uses a static library `libprun.a` . During compilation, I am loading this library file using a environment variable as below.

```nohighlight
LIBDIR = ${CUSTOM_PATH}/lib

LOADLIBS = $(LIBDIR)/libgqlcomm.a \
	           $(LIBDIR)/libgsml.a \
                   $(LIBDIR)/libprun.a \
                   $(LIBDIR)/libglis.a

```

I am not getting any errors during compilation or during running the binary in the same environment in which I compiled the binary but I am getting below error when running in a different environment as `$CUSTOM_PATH` is set to a different path.

I am getting errors only with `libprun.a` but not with other libraries.

Please suggest

---

<div class="post-metadata">

**Author:** ![Don\_Cragun](https://community.unix.com/user_avatar/community.unix.com/don_cragun/32/2682_2.png) [@Don\_Cragun](https://community.unix.com/u/Don_Cragun)\
**Post date:** [March 28, 2016, 1:30am UTC](https://community.unix.com/t/error-while-loading-shared-libraries/359427/2 "2016-03-28T01:30:26Z")

</div>

> [@vdivb](#):
>
> I am trying to run a C++ program which uses a static library `libprun.a` . During compilation, I am loading this library file using a environment variable as below.
> 
> ```plaintext
> LIBDIR = ${CUSTOM_PATH}/lib
> 
> LOADLIBS = $(LIBDIR)/libgqlcomm.a \
> $(LIBDIR)/libgsml.a \
> $(LIBDIR)/libprun.a \
> $(LIBDIR)/libglis.a
> 
> ```
> 
> I am not getting any errors during compilation or during running the binary in the same environment in which I compiled the binary but I am getting below error when running in a different environment as `$CUSTOM_PATH` is set to a different path.
> 
> I am getting errors only with `libprun.a` but not with other libraries.
> 
> Please suggest

You haven't given us much to go on here...

1. What "below error" are you getting?
2. What different environment are you talking about? Are you talking about just using a different setting for `CUSTOM_PATH` ? Are you talking about different operating systems? ???
3. How is `CUSTOM_PATH` set when your code works?
4. How is `CUSTOM_PATH` set when your code does not work?
5. Does the file `$CUSTOM_PATH/lib/libprun.a` exist in the environment when your code does not work?
6. What operating system are you using?

---

<div class="post-metadata">

**Author:** ![vdivb](https://community.unix.com/letter_avatar/vdivb/32/5_5575768a8748004e209b776fc1b2916d.png) [@vdivb](https://community.unix.com/u/vdivb)\
**Post date:** [March 28, 2016, 2:46am UTC](https://community.unix.com/t/error-while-loading-shared-libraries/359427/3 "2016-03-28T02:46:55Z")

</div>

1) What "below error" are you getting?

```plaintext
error while loading shared libraries: /home/dev/lib/libprun.a: cannot open shared object file: No such file or directory. 

```

2) What different environment are you talking about? Are you talking about just using a different setting for CUSTOM\_PATH ? Are you talking about different operating systems? ???

> [@](#):
>
> Yes, Different Setting for CUSTOM\_PATH

3) How is CUSTOM\_PATH set when your code works?

> [@](#):
>
> I have set CUSTOM\_PATH to /home/dev/ in my environment but this variable may differ in Testing environment for e.g.  
> My Environment $CUSTOM\_PATH=/home/dev/  
> Testing Environment $CUSTOM\_PATH=/home/test/

5) Does the file $CUSTOM\_PATH/lib/libprun.a exist in the environment when your code does not work?

> [@](#):
>
> File exists in below paths  
> /home/dev/lib/libprun.a (Development)  
> /home/test/lib/libprun.a (Testing)
> 
> Development path is hardcoded after compiling, as /home/dev/lib/libprun.a this is not accessible from Testing Environment, its throwing above error.

5) What operating system are you using?

> [@](#):
>
> Linux x86\_64 x86\_64 x86\_64 GNU/Linux

---

<div class="post-metadata">

**Author:** ![Don\_Cragun](https://community.unix.com/user_avatar/community.unix.com/don_cragun/32/2682_2.png) [@Don\_Cragun](https://community.unix.com/u/Don_Cragun)\
**Post date:** [March 28, 2016, 3:30am UTC](https://community.unix.com/t/error-while-loading-shared-libraries/359427/4 "2016-03-28T03:30:55Z")

</div>

By convention, a shared library would have the extension `.so` instead of `.a` .

What command do you use to build your program (in both environments)?

What output do you get from the commands:

```nohighlight
for dir in /home/test/lib /home/dev/lib
do	echo "$dir:"
	ls -ld "$dir/"libprun.*
	file "$dir/"libprun.*
done

```

---

<div class="post-metadata">

**Author:** ![vdivb](https://community.unix.com/letter_avatar/vdivb/32/5_5575768a8748004e209b776fc1b2916d.png) [@vdivb](https://community.unix.com/u/vdivb)\
**Post date:** [March 28, 2016, 4:27am UTC](https://community.unix.com/t/error-while-loading-shared-libraries/359427/5 "2016-03-28T04:27:47Z")

</div>

Here is the output which I am getting for the above piece of code.

> [@](#):
>
> /home/test/lib:  
> -rwxr-xr-x 1 divcst1 generic 44345 Mar 7 13:26 /home/test/lib/libprun.a  
> /home/test/lib/libprun.a: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, not stripped  
> /home/dev/lib:  
> ls: cannot access /home/dev/lib/libprun._: No such file or directory  
> /home/dev/lib/libprun._: cannot open `/home/dev/lib/libprun.\*' (No such file or directory)

---

<div class="post-metadata">

**Author:** ![Don\_Cragun](https://community.unix.com/user_avatar/community.unix.com/don_cragun/32/2682_2.png) [@Don\_Cragun](https://community.unix.com/u/Don_Cragun)\
**Post date:** [March 29, 2016, 1:52pm UTC](https://community.unix.com/t/error-while-loading-shared-libraries/359427/6 "2016-03-29T13:52:15Z")

</div>

You didn't my answer question about what command(s) you use to build your program, but it seems pretty obvious to me that you either need to:

1. copy or link `/home/test/lib/libprun.a` to `/home/dev/lib/libprun.a` or
2. change the way you build your program so that when it runs it loads `/home/test/lib/libprun.a` instead of `/home/dev/lib/libprun.a` .

---

<div class="post-metadata">

**Author:** ![shamrock](https://community.unix.com/letter_avatar/shamrock/32/5_5575768a8748004e209b776fc1b2916d.png) [@shamrock](https://community.unix.com/u/shamrock)\
**Post date:** [March 29, 2016, 2:35pm UTC](https://community.unix.com/t/error-while-loading-shared-libraries/359427/7 "2016-03-29T14:35:13Z")

</div>

Seems like all you need to do is modify the value of the CUSTOM\_PATH environment variable...

---

<div class="post-metadata">

**Author:** ![vdivb](https://community.unix.com/letter_avatar/vdivb/32/5_5575768a8748004e209b776fc1b2916d.png) [@vdivb](https://community.unix.com/u/vdivb)\
**Post date:** [April 1, 2016, 6:01am UTC](https://community.unix.com/t/error-while-loading-shared-libraries/359427/8 "2016-04-01T06:01:49Z")

</div>

Hi,

Attaching makefile for reference.

$INFINYS\_ROOT in above makefile is different across different environments.

Thank you
