How does Mac OSX determine which dylib to load?

℡╲_俬逩灬. 提交于 2019-12-22 09:13:18

问题


I'm trying to run Apache in Mac OSX Yosemite using MacPorts' PHP (mod_php53.so). Note that I'm not using MacPorts' Apache but Yosemite's Apache with MacPorts' PHP. This was working fine with OSX Mavericks and Mountain Lion in the past.

I get this error when running /usr/sbin/apachectl -t in Yosemite:

httpd: Syntax error on line 228 of /private/etc/apache2/httpd.conf: Cannot load /opt/local/apache2/modules/mod_php53.so into server: dlopen(/opt/local/apache2/modules/mod_php53.so, 10): Library not loaded: /opt/local/lib/libaprutil-1.0.dylib\n Referenced from: /opt/local/apache2/modules/mod_php53.so\n Reason: Incompatible library version: mod_php53.so requires version 6.0.0 or later, but libaprutil-1.0.dylib provides version 4.0.0

In fact, /opt/local/lib/libaprutil-1.0.dylib current version is 6.4.0, so it should work.

 otool -L /opt/local/lib/libaprutil-1.0.dylib
 /opt/local/lib/libaprutil-1.0.dylib:
 /opt/local/lib/libaprutil-1.0.dylib (compatibility version 6.0.0, current version 6.4.0)

I guess that Apache is loading the system's libaprutil-1.0.dylib located in /usr/lib:

otool -L /usr/lib/libaprutil-1.0.dylib 
/usr/lib/libaprutil-1.0.dylib:
/usr/lib/libaprutil-1.0.dylib (compatibility version 4.0.0, current version 4.0.0)

This is confusing because the error message clearly states that MacPorts' libaprutil was not load because of version incompatibility but I guess it is trying to use the system's libaprutil and don't know how to force Apache to load MacPorts' libaprutil.

I already tried to set the DYLD_LIBRARY_PATH environment variable, but that did not help.

Any ideas?


回答1:


This happens when the environment contains DYLD_LIBRARY_PATH=/usr/lib. Unset that and it should work.

Libraries are referenced using absolute paths on OS X. You correctly noticed /opt/local/apache2/modules/mod_php53.so references /opt/local/lib/libaprutil-1.0.dylib using its absolute path. However, in the presence of DYLD_LIBRARY_PATH the loader ignores the directory components and searches for the filename in the directories specified in DYLD_LIBRARY_PATH.

The error message you see is misleading: It is trying to tell you that an error occurred in the code that attempted to handle the /opt/local/lib/libaprutil-1.0.dylib load command (which was diverted due to the env variable).

Also, note that since MacPorts builds its PHP against MacPorts Apache, your PHP module is not necessarily binary-compatible to the system Apache. It might work for you, but that's only a coincidence.



来源:https://stackoverflow.com/questions/27490426/how-does-mac-osx-determine-which-dylib-to-load

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!