Bug #14992
closedmkmf sets DYLD_LIBRARY_PATH on macOS which breaks pkg-config
Description
When mkmf
runs pkg-config
, it sets DYLD_LIBRARY_PATH
on macOS which causes pkg-config
to not work. As an example, running
$ ruby2.5 -r mkmf -e 'pkg_config("libxml-2.0")'
writes the following to mkmf.log
.
"pkg-config --exists libxml-2.0"
dyld: Symbol not found: __cg_jpeg_resync_to_restart
Referenced from: /System/Library/Frameworks/ImageIO.framework/Versions/A/ImageIO
Expected in: /opt/local/lib/libJPEG.dylib
in /System/Library/Frameworks/ImageIO.framework/Versions/A/ImageIO
package configuration for libxml-2.0 is not found
The same behavior results from running pkg-config
with DYLD_LIBRARY_PATH
set.
$ DYLD_LIBRARY_PATH=.:/opt/local/lib pkg-config --exists libxml-2.0
dyld: Symbol not found: __cg_jpeg_resync_to_restart
Referenced from: /System/Library/Frameworks/ImageIO.framework/Versions/A/ImageIO
Expected in: /opt/local/lib/libJPEG.dylib
in /System/Library/Frameworks/ImageIO.framework/Versions/A/ImageIO
Abort trap: 6
I verified that mkmf
is responsible for setting this by writing the following pkg-config.c
file, compiling it as pkg-config
, and then running the ruby2.5
command above with .
at the front of my PATH
.
pkg-config.c
:
#include <stdio.h>
#include <stdlib.h>
int main() {
printf("DYLD_LIBRARY_PATH=%s\n", getenv("DYLD_LIBRARY_PATH"));
return 1;
}
$ ./pkg-config
DYLD_LIBRARY_PATH=(null)
$ PATH=.:$PATH ruby2.5 -r mkmf -e 'pkg_config("libxml-2.0")'
$ cat mkmf.log
"pkg-config --exists libxml-2.0"
DYLD_LIBRARY_PATH=.:/opt/local/lib
package configuration for libxml-2.0 is not found
I don't know why DYLD_LIBRARY_PATH
is being set, but I don't believe it should be. It's not respected by system binaries on macOS and macOS has supported methods of embedding run-time paths in binaries, executables, and bundles that probably should be used instead.
Updated by nobu (Nobuyoshi Nakada) over 6 years ago
- Status changed from Open to Closed
Applied in changeset trunk|r64392.
configure.ac: LIBPATHENV on macOS
- configure.ac (LIBPATHENV): use DYLD_FALLBACK_LIBRARY_PATH instead of
DYLD_LIBRARY_PATH on macOS, to honor runtime paths embedded in the
binaries. [ruby-core:88487] [Bug #14992]
Updated by nagachika (Tomoyuki Chikanaga) over 6 years ago
- Backport changed from 2.3: UNKNOWN, 2.4: UNKNOWN, 2.5: UNKNOWN to 2.3: UNKNOWN, 2.4: UNKNOWN, 2.5: REQUIRED