i'm trying to link shared library to another shared library(protobuf) with -rpath option, the problem is that the lib is in another direcory in compile time than in runtime, and -rpath option requires an existing in compile time path. (so i get an "No such file or directory" error) Is there any workaround for that? I would rather not to use LD_LIBRARY_PATH variable to solve this problem.
2 Answers
-rpath specifies the runtime library search path.
Here is a quoate from the link Program Library HOWTO
"
During development, there's the potential problem of modifying a library that's also used by many other programs -- and you don't want the other programs to use the developmental''library, only a particular application that you're testing against it. One link option you might use is ld's
rpath'' option, which specifies the runtime library search path of that particular program being compiled. From gcc, you can invoke the rpath option by specifying it this way:
-Wl,-rpath,$(DEFAULT_LIB_INSTALL_PATH)
If you use this option when building the library client program, you don't need to bother with LD_LIBRARY_PATH (described next) other than to ensure it's not conflicting, or using other techniques to hide the library. "

- 53
- 8
-
1I know all of that, the problem is when i use -Wl,-rpath,$(DIR) the linker checks if $(DIR) path exists (when compiling) and puts error (such i described upper). It's situation when that $(DIR) does not exist in compile time, it exists only in runtime. – Przemek Krzysztof Wycisk Jul 21 '15 at 15:09
I found an answer here Can I change 'rpath' in an already compiled binary?
Changing rpath after compilation solves my problem.
[edited] There is another, better approach: how to link to shared lib from shared lib with relative path

- 1
- 1

- 113
- 5