Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

On a solaris server where I don't have admin, I am compiling various software and installing in $HOME/usr, and it's mostly working. However, some of the programs that I compile in this way depend on libiconv, which I have also installed in $HOME/usr/lib. These programs will not run unless I export LD_LIBRARY_PATH=$HOME/usr/lib. If I do not do this, I get an error such as the following: rsync: fatal: open failed: No such file or directory

This is expecially bad for rsync, because it does not always operate in a shell environment, so I don't even have the option of using LD_LIBRARY_PATH to make it work. Is it possible to compile my programs such that I do not have to set LD_LIBRARY_PATH for them to run?

share|improve this question
up vote 2 down vote accepted

You want to look up rpath. With gcc, you pass -Wl,-rpath,/directory/with/library to the compile/link. I think with the Solaris compiler the flag was -R/directory/with/library, but I have no Solaris machine to check with.

share|improve this answer
I'm using GCC on solaris, and I can use GNU binutils as well. So should I use the -Wl form? – Ryan Thompson Nov 4 '10 at 22:10
Yeah, -Wl to pass to the linker, and -rpath is what binutils understands, or -Wl,-R,/directory/with/library should work as well (with solaris linker) – Rich Homolka Nov 5 '10 at 0:17
Can I put -rpath /directory/with/library in my LDFLAGS, or is it better to put -Wl,-rpath,/directory/with/library in my CFLAGS? – Ryan Thompson Nov 5 '10 at 0:58
Probably -Wl,-rpath,/path/to/dir in LDFLAGS. Makefiles rarely use ld directly but use ${CC} to drive the ld line, so -Wl is appropriate. – Rich Homolka Nov 5 '10 at 1:59
Wait, don't you mean in CFLAGS? – Ryan Thompson Nov 5 '10 at 2:31

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.