How do I specify -rpath in my makefile

c, gcc, linux

Solution

You have three options:

use LDFLAGS to specify options for `ld`

create separate rules for compilation and linking, there you can parr `-rpath=/what/ever` to `ld` directly

use `-Wl,ldoption` for `gcc` to propagate `ldoption` to linker. In your case:

`gcc ... -Wl,rpath=/what/ever ...`

Note that LD_LIBRARY_PATH serves for the dynamic linker/loader (`ldd`) not for the linker that creates executables (`ld`).

Problem

Instead of using LD_LIBRARY_PATH, I want to specify the library search path through the `-rpath` option in the makefile. How can I do that? Assume the search path is the current directory.

Original source