3

I am debugging some test failures (make test) for a Perl module on macOS. I discovered that the problem seems to be that the environment variable DYLD_LIBRARY_PATH is not forwarded to an external command run from within the Makefile. Here is a minimal example:

.PHONY: all
all:
    @echo $$DYLD_LIBRARY_PATH

On Linux from the Bash shell, I can do (or rather replace DYLD_LIBRARY_PATH with LD_LIBRARY_PATH which is used for this purpose on Linux):

$ export DYLD_LIBRARY_PATH=bar
$ make
bar

However, if I run the same Makefile on macOS Catalina 10.15.5, the variable DYLD_LIBRARY_PATH is empty:

$ export DYLD_LIBRARY_PATH=bar
$ make
# [No output]

Any idea what is the reason for this difference?

Håkon Hægland
  • 39,012
  • 21
  • 81
  • 174
  • Environment variables don't need to be specifically forwarded. Child processes inherit them automatically (and `make` doesn't do anything to disable this behaviour). I would suspect that the `$$` syntax doesn't work in macos make, but the freebsd man page shows it should. I don't have macos to test. What does `@echo '$$FOO'` (with single quotes) show? – n. m. could be an AI Aug 28 '20 at 08:50
  • It shows `$FOO` – Håkon Hægland Aug 28 '20 at 08:55
  • I cannot reproduce this behavior on macOS Mojave with the default `make` (GNU make 3.81). What is the default make on Catalina (`make --version`)? – Renaud Pacalet Aug 28 '20 at 09:00
  • @RenaudPacalet It shows GNU make 3.81. And it works here too with `$FOO`, my bad. But it does not work if I replace `FOO` with `DYLD_LIBRARY_PATH` (which was my original variable, I thought I tested that it didn't work with `FOO` also but apparently I did not). Updated question – Håkon Hægland Aug 28 '20 at 09:13
  • You forgot to edit the last `FOO` in your question. Anyway, I tested with `DYLD_LIBRARY_PATH` on macOS Mojane and GNU make 3.81 and I still cannot reproduce your problem: `make` prints `bar` on the standard output. – Renaud Pacalet Aug 28 '20 at 09:26
  • @RenaudPacalet Thanks, I have updated question hope it is correct now. So this is then something that was introduced in Catalina? (I double checked and I still get empty output) – Håkon Hægland Aug 28 '20 at 09:34
  • 9
    You are probably suffering from this: https://developer.apple.com/library/archive/documentation/Security/Conceptual/System_Integrity_Protection_Guide/RuntimeProtections/RuntimeProtections.html - if you try to set `DYLD_LIBRARY_PATH` in `bash` note that it takes no effect. – Oo.oO Aug 28 '20 at 09:37
  • @Oo.oO Thanks for the link! That seems to be the reason yes.. – Håkon Hægland Aug 28 '20 at 09:43
  • @Oo.oO Yes, that must be it. I disabled system integrity protection long time ago and completely forgot about it. – Renaud Pacalet Aug 28 '20 at 09:43
  • @RenaudPacalet Do you know for which version of macOS this protection was introduced? – Håkon Hægland Aug 28 '20 at 09:46
  • @HåkonHægland El Capitan, if I remember well. – Renaud Pacalet Aug 28 '20 at 09:49

0 Answers0