Where to put private lib files?
Stephen Hurd
shurd at sasktel.net
Thu Feb 25 06:10:20 UTC 2010
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!
More information about the freebsd-chat
mailing list