Reputation: 21665
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.
Upvotes: 3
Views: 8233
Reputation: 58754
The -rpath
flag needs to be passed to the linker. Prefix all flags with -Wl
to have gcc pass them to ld, e.g.
LDFLAGS = -Wl,-rpath -Wl,.
Upvotes: 1
Reputation: 980
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
).
Upvotes: 3
Reputation: 43578
Example
LDFLAGS += --rpath-link /home/hp/Desktop/staging_dir/target-mips_uClibc-0.9.30.1/root-brcmref/lib/ld-uClibc.so.0
Example of make file:
all: test
%.o: %.c
$(CC) $(CFLAGS) -c -o $@ $^
test: test1.o test2.o
$(CC) $(LDFLAGS) -o $@ $^
Upvotes: 0