# Where to put private lib files?



## jronald (Feb 23, 2010)

For example, a lib file is to be used only by one application,
and I don't want to pollute any system wide things (eg: system wide lib directories, system wide variables),
where to put it?
Thanks.


----------



## segfault (Feb 23, 2010)

Until someone more knowledgeable answers I will offer this:
You may be able to stick your lib anywhere you wish (such as in your home dir maybe: ~/lib) and then just run the "ldconfig" command with your chosen dir as an argument.

So if I'm understanding correctly from ldconfig(8), this might do the trick:

```
ldconfig /home/username/lib
```


Good luck!


----------



## DutchDaemon (Feb 23, 2010)

Use `ldconfig -m` rather.


----------



## jronald (Feb 24, 2010)

Is there any method to localize the lib file, without polluting any system wide things?


----------



## Alt (Feb 24, 2010)

You can set env var LD_LIBRARY_PATH to set search path for lib
Hower, this ignored by suid apps

You can put into makefile
	
	



```
LDFLAGS = -rpath /path/to/lib/
```
To encode search path into app


----------



## jronald (Feb 25, 2010)

Alt said:
			
		

> You can set env var LD_LIBRARY_PATH to set search path for lib
> Hower, this ignored by suid apps
> 
> You can put into makefile
> ...




But LD_LIBRARY_PATH is also system wide.


----------



## Alt (Feb 25, 2010)

jronald said:
			
		

> But LD_LIBRARY_PATH is also system wide.


Have you tried?  



```
# ./fcgi-server
/libexec/ld-elf.so.1: Shared object "libsoci_core.so" not found, required by "fcgi-server"
# setenv LD_LIBRARY_PATH /home/alt/projects/cpp/fcgi-server
# ./fcgi-server
fork ok
```
Anyway you can do -rpath


----------



## jronald (Feb 27, 2010)

Alt said:
			
		

> Have you tried?
> 
> 
> 
> ...



I have tried -rpath, it's not ideal. For example:
Let the current directory (.) to be the param of rpath,
and the shared object file and binary file be in the same directory, and the current working directory be different.
It doesn't work.


----------



## Brandybuck (Feb 27, 2010)

jronald said:
			
		

> Is there any method to localize the lib file, without polluting any system wide things?



What do you mean "localize". If you want it available for just one user, then use LD_LIBRARY_PATH. It will only "pollute" the current terminal session.

Or you want write a two line script to run your executable:

export LD_LIBRARY_PATH=~/lib/libfunky.so
~/bin/funkyapp


----------



## jronald (Feb 27, 2010)

Brandybuck said:
			
		

> What do you mean "localize". If you want it available for just one user, then use LD_LIBRARY_PATH. It will only "pollute" the current terminal session.
> 
> Or you want write a two line script to run your executable:
> 
> ...



I mean the shared library file can be found only by the binary file by default.
Localizing is always better when it is efficient enough, isn't it?


----------

