diff --git a/config/nim.cfg b/config/nim.cfg
index 038c3c9be..d596d6df7 100644
--- a/config/nim.cfg
+++ b/config/nim.cfg
@@ -60,8 +60,8 @@
 path="$lib/pure"
 
 @if not windows:
-  nimblepath="/opt/nimble/pkgs2/"
-  nimblepath="/opt/nimble/pkgs/"
+  nimblepath="@PREFIX@/lib/nimble/pkgs2/"
+  nimblepath="@PREFIX@/lib/nimble/pkgs/"
 @else:
   # TODO:
 @end
@@ -219,6 +219,16 @@
   gcc.objc.options.linker = "-framework Foundation"
   llvm_gcc.objc.options.linker = "-framework Foundation"
   clang.objc.options.linker = "-framework Foundation"
+
+  gcc.options.linker %= "${gcc.options.linker} -Wl,-rpath,@PREFIX@/lib/libgcc,-rpath,@PREFIX@/lib,-rpath,/System/Library/Frameworks,-rpath,/usr/lib"
+  gcc.cpp.options.linker %= "${gcc.cpp.options.linker} -Wl,-rpath,@PREFIX@/lib/libgcc,-rpath,@PREFIX@/lib,-rpath,/System/Library/Frameworks,-rpath,/usr/lib"
+  llvm_gcc.options.linker %= "${llvm_gcc.options.linker} -Wl,-rpath,@PREFIX@/lib,-rpath,/System/Library/Frameworks,-rpath,/usr/lib"
+  llvm_gcc.cpp.options.linker %= "${llvm_gcc.cpp.options.linker} -Wl,-rpath,@PREFIX@/lib,-rpath,/System/Library/Frameworks,-rpath,/usr/lib"
+  clang.options.linker %= "${clang.options.linker} -Wl,-rpath,@PREFIX@/lib,-rpath,/System/Library/Frameworks,-rpath,/usr/lib"
+  clang.cpp.options.linker %= "${clang.cpp.options.linker} -Wl,-rpath,@PREFIX@/lib,-rpath,/System/Library/Frameworks,-rpath,/usr/lib"
+
+  cincludes: "@PREFIX@/include"
+  clibdir: "@PREFIX@/lib"
 @end
 
 # Options for FreeBSD, OpenBSD, NetBSD linker to add locations for searching
diff --git a/lib/pure/ssl_certs.nim b/lib/pure/ssl_certs.nim
index d60cd22eb..3518a6e88 100644
--- a/lib/pure/ssl_certs.nim
+++ b/lib/pure/ssl_certs.nim
@@ -16,6 +16,7 @@ import std/[os, strutils]
 
 when defined(macosx):
   const certificatePaths = [
+    "@PREFIX@/etc/openssl/cert.pem",
     "/etc/ssl/cert.pem",
     "/System/Library/OpenSSL/certs/cert.pem"
   ]

--- a/lib/pure/encodings.nim	2026-02-23 10:50:45.000000000 +0800
+++ b/lib/pure/encodings.nim	2026-03-17 01:58:22.000000000 +0800
@@ -293,7 +293,7 @@
   when defined(haiku):
     const iconvDll = "libiconv.so"
   elif defined(macosx):
-    const iconvDll = "libiconv.dylib"
+    const iconvDll = "@PREFIX@/lib/libiconv.dylib"
   else:
     const iconvDll = "(libc.so.6|libiconv.so)"
 
@@ -321,12 +321,12 @@
     {.pragma: importIconv, cdecl, dynlib: iconvDll.}
 
   proc iconvOpen(tocode, fromcode: cstring): EncodingConverter {.
-    importc: "iconv_open", importIconv.}
+    importc: "libiconv_open", importIconv.}
   proc iconvClose(c: EncodingConverter) {.
-    importc: "iconv_close", importIconv.}
+    importc: "libiconv_close", importIconv.}
   proc iconv(c: EncodingConverter, inbuf: ptr cstring, inbytesLeft: ptr csize_t,
              outbuf: ptr cstring, outbytesLeft: ptr csize_t): csize_t {.
-    importc: "iconv", importIconv.}
+    importc: "libiconv", importIconv.}
 
 proc getCurrentEncoding*(uiApp = false): string =
   ## Retrieves the current encoding. On Unix, "UTF-8" is always returned.

diff --git a/tests/manyloc/keineschweine/lib/glx.nim b/tests/manyloc/keineschweine/lib/glx.nim
index ce02835bd..4d6db7922 100644
--- a/tests/manyloc/keineschweine/lib/glx.nim
+++ b/tests/manyloc/keineschweine/lib/glx.nim
@@ -31,7 +31,7 @@ when defined(windows):
     dllname = "GL.dll"
 elif defined(macosx):
   const
-    dllname = "/usr/X11R6/lib/libGL.dylib"
+    dllname = "@PREFIX@/lib/libGL.dylib"
 else:
   const
     dllname = "libGL.so"

