1
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:
ld.so.1: rsync: fatal: libiconv.so.2: 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?
I'm using GCC on solaris, and I can use GNU binutils as well. So should I use the
-Wl
form? – Ryan C. Thompson – 2010-11-04T22:10:00.770Yeah, -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 – 2010-11-05T00:17:58.713
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 C. Thompson – 2010-11-05T00:58:51.670Probably -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 – 2010-11-05T01:59:24.127
Wait, don't you mean in CFLAGS? – Ryan C. Thompson – 2010-11-05T02:31:51.607
To be honest I'd check in either way. You can test your executable possibly. On Linux I use
readelf -d
to see the section for RPATH, this may be doable with gnu binutils on Solaris. BUT I meantLDFLAGS
. Think ofgcc
not as a compiler, but as a build tool driver. One of the things it does is drive the link stage. The link will (probably) begcc -o executable $OBJS $LDFLAGS $LIBS
. So, gcc wil pass (because of -Wl) to ld. – Rich Homolka – 2010-11-05T03:05:49.347When I add this to my CFLAGS, I get
ld: fatal: option -dn and -P are incompatible
during./configure
, after which it says the the C compiler can't create executables. GNU ld doesn't even have a -P option, so I'm pretty sure GCC is using the Solaris linker, even though I have GNU ld installed in a higher-priority path. – Ryan C. Thompson – 2010-11-05T05:34:52.057I tried with -R instead of -rpath, and it seems to work. I would still like to know how to use my own ld, but I guess that's another question. – Ryan C. Thompson – 2010-11-05T06:03:05.190