diff --git a/db-benchmark-test/Makefile b/db-benchmark-test/Makefile
index 78421dbd71b4c25b321eaa90f432852a6311d4a9..a721718c0194fec10d9b885def857e256954b8f9 100644
--- a/db-benchmark-test/Makefile
+++ b/db-benchmark-test/Makefile
@@ -19,7 +19,7 @@ BDB_CPPFLAGS =
 BDB_LDFLAGS = -ldb
 endif
 TDB_CPPFLAGS = -I../include
-TDB_LDFLAGS = -L../lib -ltokudb -Wl,-rpath=$(PWD)/../lib
+TDB_LDFLAGS = -L../lib -ltokudb -Wl,-rpath,$(PWD)/../lib
 
 TARGET_BDB = db-benchmark-test-bdb
 TARGET_TDB = db-benchmark-test-tokudb
diff --git a/src/Makefile b/src/Makefile
index 2d0afdd1047703d0755267ea794125d8aea1f689..2b0fadc5bfcd70eccb78144920c48a7c3dad6798 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -13,10 +13,12 @@ CPPFLAGS += -D_GNU_SOURCE -D_THREAD_SAFE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_S
 ifneq ($(OSX),)
 LIBEXT=dylib
 SHARED=-dynamiclib
+RPATHNAME=-install_name @rpath/$(LIBNAME).$(LIBEXT)
 CFLAGS+=-fno-common
 else
 LIBEXT=so
 SHARED=-shared
+RPATHNAME=
 endif
 
 .PHONY: install logformat
@@ -50,7 +52,7 @@ LOCKTREE_BINS  = lock_tree/locktree.o lock_tree/rth.o lock_tree/lth.o $(RANGETRE
 
 
 $(LIBNAME).$(LIBEXT): $(DBBINS) $(LOCKTREE_BINS)
-	cc  $(CPPFLAGS) $^ $(SHARED) -o $@ $(CFLAGS) -lz
+	cc  $(CPPFLAGS) $^ $(SHARED) -o $@ $(CFLAGS) -lz $(RPATHNAME)
 
 $(LIBNAME).a: $(DBBINS) $(LOCKTREE_BINS)
 	$(AR) rv $@ $^