Set library install names at build time. This may not be the best method but the build system is nonstandard and complicated and the best way may require more restructuring tham I'm prepared to do. Remove code that rewrites install names at install time which didn't work for several reasons: 1. $(wildcard) was evaluated before the dylibs had been created so it expanded to the empty string unless you ran it a second time 2. The build system doesn't support DESTDIR so we include the dest dir in the value of ESMF_INSTALL_LIBDIR so the rewritten install names would contain the dest dir too 3. The wrong install names were baked into the executables when they were built and there was no makefile code to rewrite them --- build/common.mk.orig 2022-10-25 07:04:55.000000000 +0900 +++ build/common.mk 2022-11-13 14:06:42.000000000 +0900 @@ -1146,6 +1146,7 @@ ESMF_SL_SUFFIX = so ifeq ($(ESMF_OS),Darwin) ESMF_SL_SUFFIX = dylib +ESMF_SL_LIBOPTS += -install_name $$INSTALLNAME endif ifeq ($(ESMF_OS),Cygwin) ESMF_SL_SUFFIX = dll.a @@ -3999,12 +4000,14 @@ do \ if [ -f $$NEXTLIB.$(ESMF_LIB_SUFFIX) ] ; then \ $(ESMF_RM) $$NEXTLIB.$(ESMF_SL_SUFFIX) ; \ + INSTALLNAME=$(ESMF_INSTALL_LIBDIR_ABSPATH)/$$NEXTLIB.$(ESMF_SL_SUFFIX) ;\ echo Converting $$NEXTLIB.a to $$NEXTLIB.$(ESMF_SL_SUFFIX) ;\ mkdir tmp_$$NEXTLIB ;\ cd tmp_$$NEXTLIB ;\ $(ESMF_AREXTRACT) ../$$NEXTLIB.$(ESMF_LIB_SUFFIX) ;\ echo $(ESMF_SL_LIBLINKER) $(ESMF_SL_LIBOPTS) -o $(ESMF_LDIR)/$$NEXTLIB.$(ESMF_SL_SUFFIX) *.o $(ESMF_SL_LIBLIBS) ;\ $(ESMF_SL_LIBLINKER) $(ESMF_SL_LIBOPTS) -o $(ESMF_LDIR)/$$NEXTLIB.$(ESMF_SL_SUFFIX) *.o $(ESMF_SL_LIBLIBS) ;\ + INSTALLNAME=$(ESMF_INSTALL_LIBDIR_ABSPATH)/$$NEXTLIB\_fullylinked.$(ESMF_SL_SUFFIX) ;\ echo Converting $$NEXTLIB.$(ESMF_SL_SUFFIX) to $$NEXTLIB\_fullylinked.$(ESMF_SL_SUFFIX) ;\ echo $(ESMF_SL_LIBLINKER) $(ESMF_SL_LIBOPTS) -o $(ESMF_LDIR)/$$NEXTLIB\_fullylinked.$(ESMF_SL_SUFFIX) *.o $(ESMF_CXXLINKOPTS) $(ESMF_CXXLINKPATHS) $(ESMF_CXXLINKRPATHS) $(ESMF_CXXLINKLIBS) ;\ $(ESMF_SL_LIBLINKER) $(ESMF_SL_LIBOPTS) -o $(ESMF_LDIR)/$$NEXTLIB\_fullylinked.$(ESMF_SL_SUFFIX) *.o $(ESMF_CXXLINKOPTS) $(ESMF_CXXLINKPATHS) $(ESMF_CXXLINKRPATHS) $(ESMF_CXXLINKLIBS) ;\ --- makefile.orig 2022-10-25 07:04:55.000000000 +0900 +++ makefile 2022-11-13 20:37:08.000000000 +0900 @@ -705,17 +705,6 @@ ifeq ($(ESMF_PIO),internal) cp -f $(ESMF_LIBDIR)/libpioc.* $(ESMF_INSTALL_LIBDIR_ABSPATH) endif -ifneq (,$(filter $(ESMF_OS),Darwin DARWIN darwin)) - @for lib in $(ESMF_INSTALL_LIBDIR_ABSPATH)/libesmf*.dylib foo ; do \ - if [ $$lib != "foo" ]; then \ - install_name_tool -id "$$lib" $$lib ; \ - fi ; \ - if [ $$lib == "$(ESMF_INSTALL_LIBDIR_ABSPATH)/libesmftrace_preload.dylib" ]; then \ - install_name_tool -change "$(ESMF_LIBDIR)/libesmf.dylib" \ - "$(ESMF_INSTALL_LIBDIR_ABSPATH)/libesmf.dylib" $$lib; \ - fi ; \ - done -endif ifeq ($(ESMF_TRACE_LIB_BUILD),ON) ifeq ($(ESMF_TRACE_BUILD_SHARED),ON) $(MAKE) ESMF_PRELOADDIR=$(ESMF_INSTALL_LIBDIR_ABSPATH) build_preload_script --- src/Infrastructure/Trace/preload/makefile.orig 2021-10-26 16:39:51.000000000 -0500 +++ src/Infrastructure/Trace/preload/makefile 2022-04-25 19:25:09.000000000 -0500 @@ -32,6 +32,8 @@ endif tracelib_preload: preload.o preload_io.o preload_mpi.o wrappers.o wrappers_io.o wrappers_mpi.o + @INSTALLNAME=$(ESMF_INSTALL_LIBDIR_ABSPATH)/libesmftrace_preload.$(ESMF_SL_SUFFIX) ;\ + echo $(ESMF_SL_LIBLINKER) $(ESMF_SL_LIBOPTS) -o $(ESMF_LDIR)/libesmftrace_preload.$(ESMF_SL_SUFFIX) $^ $(ESMF_CXXLINKOPTS) $(ESMF_CXXLINKPATHS) $(ESMF_CXXLINKRPATHS) $(ESMF_CXXLINKLIBS) $(ESMF_TRACE_ESMFLIB) ;\ $(ESMF_SL_LIBLINKER) $(ESMF_SL_LIBOPTS) -o $(ESMF_LDIR)/libesmftrace_preload.$(ESMF_SL_SUFFIX) $^ $(ESMF_CXXLINKOPTS) $(ESMF_CXXLINKPATHS) $(ESMF_CXXLINKRPATHS) $(ESMF_CXXLINKLIBS) $(ESMF_TRACE_ESMFLIB) $(MAKE) ESMF_PRELOADDIR=$(ESMF_LIBDIR) build_preload_script