Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Where to put private lib files?

2 views
Skip to first unread message

Ronald

unread,
Feb 22, 2010, 9:40:05 PM2/22/10
to freebs...@freebsd.org
I think the global lib directories is not so good, because it should be for
public libs.

The libs private to one application, where to put them?

Thanks.

Alex Moura

unread,
Feb 22, 2010, 10:48:57 PM2/22/10
to Ronald, freebs...@freebsd.org
2010/2/22 Ronald <foll...@163.com>

> I think the global lib directories is not so good, because it should be for
> public libs.
>
> The libs private to one application, where to put them?
>
>

/usr/local/lib ?

Charlie Kester

unread,
Feb 22, 2010, 11:25:41 PM2/22/10
to freebs...@freebsd.org

/usr/local/lib/appname ?

In which case it would be up to the app to know where to find its libs.

Dag-Erling Smørgrav

unread,
Feb 23, 2010, 6:56:29 AM2/23/10
to Stephen Hurd, Ronald, freebs...@freebsd.org
Stephen Hurd <sh...@sasktel.net> writes:
> Dag-Erling Smørgrav <d...@des.no> writes:
> > The canonical location for ports is ${LIBDIR}/${PORTNAME}, but
> > remember that unless these are run-time loadable modules, this
> > directory must be in the library search path when you run the app.
> > This means that you either have to ldconfig the directory using an
> > rc_subr script (which defeats the purpose of having a private
> > library directory) or install a wrapper that sets LD_LIBRARY_PATH
> > before execing the real binary.
> You can also compile in a search path.

Not PREFIX-safe, hence not allowed in ports unless there is no other
solution.

DES
--
Dag-Erling Smørgrav - d...@des.no

Dag-Erling Smørgrav

unread,
Feb 23, 2010, 4:39:42 AM2/23/10
to Ronald, freebs...@freebsd.org

The canonical location for ports is ${LIBDIR}/${PORTNAME}, but remember


that unless these are run-time loadable modules, this directory must be
in the library search path when you run the app. This means that you
either have to ldconfig the directory using an rc_subr script (which
defeats the purpose of having a private library directory) or install a
wrapper that sets LD_LIBRARY_PATH before execing the real binary.

DES

Stephen Hurd

unread,
Feb 23, 2010, 5:57:46 AM2/23/10
to Dag-Erling Smørgrav, Ronald, freebs...@freebsd.org

You can also compile in a search path.

Stephen Hurd

unread,
Feb 24, 2010, 12:59:06 AM2/24/10
to Dag-Erling Smørgrav, Ronald, freebs...@freebsd.org
Dag-Erling Smørgrav wrote:
>>> The canonical location for ports is ${LIBDIR}/${PORTNAME}, but
>>> remember that unless these are run-time loadable modules, this
>>> directory must be in the library search path when you run the app.
>>> This means that you either have to ldconfig the directory using an
>>> rc_subr script (which defeats the purpose of having a private
>>> library directory) or install a wrapper that sets LD_LIBRARY_PATH
>>> before execing the real binary.
>>>
>> You can also compile in a search path.
>>
>
> Not PREFIX-safe, hence not allowed in ports unless there is no other
> solution

Eh? It doesn't need to be an absolute path.

Stephen Hurd

unread,
Feb 25, 2010, 1:10:16 AM2/25/10
to Dag-Erling Smørgrav, Ronald, freebs...@freebsd.org
Stephen Hurd wrote:
>>> You can also compile in a search path.
>>>
>>
>> Not PREFIX-safe, hence not allowed in ports unless there is no other
>> solution
>
> Eh? It doesn't need to be an absolute path.

To follow up on this for you Ronald, to compile in a PREFIX-safe
relative library path, you need to pass -z origin -rpath
$ORIGIN/../lib/pkgname to the linker... that is a literal $ so assuming
you're using regular make files and gcc as the linker, you would add
this line:

LDFLAGS += -Wl,-z,origin,-rpath,\$$ORIGIN/../lib/$(PORTNAME)

You need to double the $ so that make doesn't expand $ORIGIN for you and
the \ is for the shell. The command line would be something like this:
cc -O2 -pipe -march=pentium4 -Wl,-z,origin,-rpath,\$ORIGIN/../lib/test
test.c -L. -ltest -o test

You may need to fiddle around to get the literal $ in there, a strings
on the compiled binary would include ``$ORIGIN/../lib/test'' (without
the quotes of course).

The reason you *need* to use $ORIGIN is that if you don't the relative
path will be to whatever the pwd is when the process is started making
them effectively random.

Have fun!

0 new messages