Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify RPATH in a makefile?

Tags:

People also ask

What is Rpath in Linux?

In computing, rpath designates the run-time search path hard-coded in an executable file or library. Dynamic linking loaders use the rpath to find required libraries. Specifically, it encodes a path to shared libraries into the header of an executable (or another shared library).

What does Rpath link do?

The -rpath-link option may specify a sequence of directory names either by specifying a list of names separated by colons, or by appearing multiple times. The linker uses the following search paths to locate required shared libraries.

What is Ldflags in Makefile?

LDFLAGS: Extra flags to give to compilers when they are supposed to invoke the linker, 'ld', such as -L. Libraries (-lfoo) should be added to the LDLIBS variable instead. LDLIBS: Library flags or names given to compilers when they are supposed to invoke the linker, 'ld'.


I'm trying to specify rpath in my binary. My makefile looks like this-

CC=gcc 
CFLAGS=-Wall
LDFLAGS= -rpath='../libs/'
main: main.c  
    gcc -o main main.c

clean:
    rm -f main main.o 

But when I query rpath using command readelf -a ./main | grep rpath I get nothing I've tried specifying rpath as LDFLAGS= "-rpath=../libs/" but even that doesn't seem to work.

Can someone please post an example on how should I specify rpath in a makefile?

GCC and ld versions are-

gcc (Ubuntu/Linaro 4.5.2-8ubuntu4) 4.5.2
GNU ld (GNU Binutils for Ubuntu) 2.21.0.20110327