Mac OSX如何确定要加载的Dylib? [英] How does Mac OSX determine which dylib to load?

查看:346
本文介绍了Mac OSX如何确定要加载的Dylib?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用MacPorts的PHP(mod_php53.so)在Mac OSX Yosemite中运行Apache.请注意,我使用的不是MacPorts的Apache,而是优胜美地的Apache和MacPorts的PHP.过去与OSX Mavericks和Mountain Lion配合使用时效果很好.

在优胜美地中运行/usr/sbin/apachectl -t时出现此错误:

httpd:/private/etc/apache2/httpd.conf的第228行的语法错误:无法将/opt/local/apache2/modules/mod_php53.so加载到服务器中:dlopen(/opt/local/apache2/modules/mod_php53.so,10):库未加载:/opt/local/lib/libaprutil-1.0.dylib\n引用自:/opt/local/apache2/modules/mod_php53.so\n原因:库版本不兼容:mod_php53.因此需要版本6.0.0或更高版本,但libaprutil-1.0.dylib提供版本4.0.0

事实上,/opt/local/lib/libaprutil-1.0.dylib的当前版本是6.4.0,因此它应该可以工作.

 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)

我猜想Apache正在加载位于/usr/lib中的系统的libaprutil-1.0.dylib:

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)

这令人困惑,因为错误消息明确指出由于版本不兼容而未加载MacPorts的libaprutil,但我想它正在尝试使用系统的libaprutil,并且不知道如何强制Apache加载MacPorts的libaprutil. /p>

我已经尝试设置DYLD_LIBRARY_PATH环境变量,但这无济于事.

有什么想法吗?

解决方案

当环境包含DYLD_LIBRARY_PATH=/usr/lib时,就会发生这种情况.取消设置,它应该可以工作.

在OS X上使用绝对路径来引用库.您已经正确地注意到/opt/local/apache2/modules/mod_php53.so使用其绝对路径来引用/opt/local/lib/libaprutil-1.0.dylib.但是,在DYLD_LIBRARY_PATH存在的情况下,加载程序将忽略目录组件,并在DYLD_LIBRARY_PATH中指定的目录中搜索文件名.

您看到的错误消息具有误导性:它试图告诉您尝试处理/opt/local/lib/libaprutil-1.0.dylib加载命令的代码中发生了错误(由于env变量而被改编了).

此外,请注意,由于MacPorts是根据MacPorts Apache构建其PHP的,因此您的PHP模块不一定与系统Apache二进制兼容.它可能对您有用,但这只是一个巧合.

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?

解决方案

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.

这篇关于Mac OSX如何确定要加载的Dylib?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆