title: How to include correctly -Wl,-rpath,$ORIGIN linker argument in a Makefile?
body: <p>I'm preparing a c++ app on linux (Ubuntu 16.04) with the use of a few poco libraries which I have dynamically linked. I have project folder that consists of : include, bin, lib , src and build folders and the relevant Makefile. So far  I used  the following Makefile which got the libraries from /usr/local/lib</p>
  
  <pre><code>CC := g++ 
  
  # Folders
  SRCDIR := src
  BUILDDIR := build
  TARGETDIR := bin
  
  # Targets
  EXECUTABLE := C++_APP
  TARGET := $(TARGETDIR)/$(EXECUTABLE)
  
  SRCEXT := cpp
  SOURCES := $(shell find $(SRCDIR) -type f -name *.$(SRCEXT))
  OBJECTS := $(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCES:.$(SRCEXT)=.o))
  CFLAGS := -c -Wall
  INC := -I include -I /usr/local/include
  LIB := -L /usr/local/lib -lPocoFoundation -lPocoNet -lPocoUtil 
  
  $(TARGET): $(OBJECTS)
  @echo " Linking..."
  @echo " $(CC) $^ -o $(TARGET) $(LIB)"; $(CC) $^ -o $(TARGET) $(LIB)
  
  $(BUILDDIR)/%.o: $(SRCDIR)/%.$(SRCEXT)
  @mkdir -p $(BUILDDIR)
  @echo " $(CC) $(CFLAGS) $(INC) -c -o $@ $&lt;"; $(CC) $(CFLAGS) $(INC) -c -o $@      $&lt;
  
  clean:
  @echo " Cleaning..."; 
  @echo " $(RM) -r $(BUILDDIR) $(TARGET)"; $(RM) -r $(BUILDDIR) $(TARGET)
  
  .PHONY: clean 
  </code></pre>
  
  <p>Now I'd like during running the linker to search for libraries only in project lib folder without changing LD_LIBRARY_PATH or editing ld.so.conf. So I searched and I found that this can be achieved by the linker argument -Wl,rpath,$ORIGIN. So I assume that I need to add the following statement  </p>
  
  <pre><code>LDFLAGS := -Wl,-rpath,$ORIGIN/../lib
  </code></pre>
  
  <p>and change the the LIB statement as following:</p>
  
  <pre><code>LIB := -L $ORIGIN/../lib -lPocoFoundation -lPocoNet -lPocoUtil 
  </code></pre>
  
  <p>However it still get the libraries from the default directory (usr/local/lib) , since I tested it with no library on the project lib folder. What have I done wrong?</p>