从ld: library not found for -lzookeeper_mt 看ZooKeeper 在Mac OS EI Capitan的安装方式

本文涉及的产品
图片翻译,图片翻译 100张
文档翻译,文档翻译 1千页
任务调度 XXL-JOB 版免费试用,400 元额度,开发版规格
简介: 版权声明:本文为半吊子子全栈工匠(wireless_com,同公众号)原创文章,未经允许不得转载。
版权声明:本文为半吊子子全栈工匠(wireless_com,同公众号)原创文章,未经允许不得转载。 https://blog.csdn.net/wireless_com/article/details/52326964

起因

同事的Mac 升级到EI Capitan后,zookeeper 的python client 用不了了。zookeeper 的python client 一般使用的有两种:zkpython和kazoo。 kazoo是纯python的实现,zkpython是zookeeper c client 的python binding。 这里使用的是zkpython。

现象

重新编译安装,报错如下:


sudo python setup.py build
Password:
running build
running build_ext
building 'zookeeper' extension
cc -fno-strict-aliasing -fno-common -dynamic -arch i386 -arch x86_64 -g -Os -pipe -fno-common -fno-strict-aliasing -fwrapv -DENABLE_DTRACE -DMACOSX -DNDEBUG -Wall -Wstrict-prototypes -Wshorten-64-to-32 -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch i386 -arch x86_64 -pipe -I/usr/include/c-client-src -I/usr/local/include/c-client-src -I/usr/include/zookeeper -I/usr/local/include/zookeeper -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c zookeeper.c -o build/temp.macosx-10.11-intel-2.7/zookeeper.o
zookeeper.c:362:17: warning: implicit conversion loses integer precision:
      'Py_ssize_t' (aka 'long') to 'int32_t' (aka 'int') [-Wshorten-64-to-32]
  acls->count = PyList_Size( pyacls );
              ~ ^~~~~~~~~~~~~~~~~~~~~
1 warning generated.
cc -bundle -undefined dynamic_lookup -arch i386 -arch x86_64 -Wl,-F. build/temp.macosx-10.11-intel-2.7/zookeeper.o -lzookeeper_mt -o build/lib.macosx-10.11-intel-2.7/zookeeper.so
ld: library not found for -lzookeeper_mt
clang: error: linker command failed with exit code 1 (use -v to see invocation)
error: command 'cc' failed with exit status 1

原因分析

错误的核心是 ld: library not found for -lzookeeper_mt,zookeeper的多线程c语言库没有找到。

检查zookeeper 3.4.7 的安装结果,发现/usr/lib 中并没有生成最新的libzkmt 相关库。

原因何在呢?
老规矩,检查环境,感觉是EI Capitan 的权限问题。经历了XCode编译器代码被注入的事件后, Mac OS X El Capitan系统的升级,启用了更高的安全性保护机制:系统完整性保护System Integrity Protection (SIP)。简单来讲就是更加强制性的保护系统相关的文件夹。开发者不能直接操作相关的文件内容。

苹果官方给出的解释:

System Integrity Protection is a security technology in OS X El Capitan that’s designed to help prevent potentially malicious software from modifying protected files and folders on your Mac. 
In OS X, the “root” user account previously had no permission restrictions and could access any system folder or application on your Mac. Software gained root-level access when you entered your administrator name and password to install it and could then modify or overwrite any system file or application. 
System Integrity Protection restricts the root account and limits the actions that the root user can perform on protected parts of OS X. 
Paths and applications protected by System Integrity Protection include: 
/System 
/usr 
/bin 
/sbin 
Apps that are pre-installed with OS X 
Paths and applications that third-party apps and installers can write to include: 
/Applications 
/Library 
/usr/local 
System Integrity Protection is designed to allow modifications of these protected parts only by processes that are signed by Apple and have special entitlements to write to system files, like Apple software updates and Apple installers. 
Apps that you download from the Mac App Store already work with System Integrity Protection. Other third-party software that conflicts with System Integrity Protection might be set aside when you upgrade to OS X El Capitan. 
System Integrity Protection also helps prevent software from changing your startup volume. To boot your Mac from a different volume, you can use the Startup Disk pane in System Preferences or you can hold down the Option key while you reboot, and select a volume from the list. 
Information about products not manufactured by Apple, or independent websites not controlled or tested by Apple, is provided without recommendation or endorsement. Apple assumes no responsibility with regard to the selection, performance, or use of third-party websites or products. Apple makes no representations regarding third-party website accuracy or reliability. Risks are inherent in the use of the Internet. Contact the vendor for additional information. Other company and product names may be trademarks of their respective owners. 
https://support.apple.com/en-us/HT204899

初步尝试

原因基本找到,重新编译安装zookeeper 3.4.7,指定安装路径为/usr/local

$sudo ./configure --prefix=/usr/local
$sudo make
$sudo make install

编译安装成功,在/usr/local/lib 中已经生成了zookeeper 的相关库。

现在,重新编译zkpython 0.4.2, 发现问题依旧!

解决

在编译链接的时候如何指定自定义的库路径呢?研读setup.py 的相关文档,就很快得到答案了。

修改zkpython 的setup.py 文件,增加zookeeper的库路径:

zookeepermodule = Extension("zookeeper",
                            sources=["zookeeper.c"],
                            include_dirs=[ "/usr/local/include/c-client-src",
                                  "/usr/local/include/zookeeper"],
                            library_dirs=["/usr/local/lib"],
                            libraries=["zookeeper_mt"],
                            )

重新安装zkpython,sudo python setup.py install, 安装成功。

检验确认

验证一下,

$ python
Python 2.7.11 |Anaconda 2.5.0 (x86_64)| (default, Dec  6 2015, 18:57:58) 
[GCC 4.2.1 (Apple Inc. build 5577)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
>>> import zookeeper
>>> 

一起正常了,可以自由使用zookeeper 强大的配置管理能力了。

目录
相关文章
|
2月前
|
Ubuntu Linux Shell
Ubuntu gnome WhiteSur-gtk-theme类mac主题正确安装和卸载方式
通过这个过程,用户不仅可以定制自己的桌面外观,还可以学习到更多关于 Linux 系统管理的知识,从而更好地掌握系统配置和主题管理的技巧。
175 12
|
2月前
|
监控 Shell Linux
Android调试终极指南:ADB安装+多设备连接+ANR日志抓取全流程解析,覆盖环境变量配置/多设备调试/ANR日志分析全流程,附Win/Mac/Linux三平台解决方案
ADB(Android Debug Bridge)是安卓开发中的重要工具,用于连接电脑与安卓设备,实现文件传输、应用管理、日志抓取等功能。本文介绍了 ADB 的基本概念、安装配置及常用命令。包括:1) 基本命令如 `adb version` 和 `adb devices`;2) 权限操作如 `adb root` 和 `adb shell`;3) APK 操作如安装、卸载应用;4) 文件传输如 `adb push` 和 `adb pull`;5) 日志记录如 `adb logcat`;6) 系统信息获取如屏幕截图和录屏。通过这些功能,用户可高效调试和管理安卓设备。
|
8月前
|
iOS开发 MacOS Windows
Mac air使用Boot Camp安装win10 ,拷贝 Windows 文件时出错
Mac air使用Boot Camp安装win10 ,拷贝 Windows 文件时出错
|
5月前
|
存储 SpringCloudAlibaba Java
【SpringCloud Alibaba系列】一文全面解析Zookeeper安装、常用命令、JavaAPI操作、Watch事件监听、分布式锁、集群搭建、核心理论
一文全面解析Zookeeper安装、常用命令、JavaAPI操作、Watch事件监听、分布式锁、集群搭建、核心理论。
【SpringCloud Alibaba系列】一文全面解析Zookeeper安装、常用命令、JavaAPI操作、Watch事件监听、分布式锁、集群搭建、核心理论
|
6月前
|
开发工具 git 开发者
「Mac畅玩鸿蒙与硬件3」鸿蒙开发环境配置篇3 - DevEco Studio插件安装与配置
本篇将专注于如何在 DevEco Studio 中安装和配置必要的插件,以增强开发功能和提升效率。通过正确配置插件,开发流程能够得到简化,开发体验也会更加顺畅。
263 1
「Mac畅玩鸿蒙与硬件3」鸿蒙开发环境配置篇3 - DevEco Studio插件安装与配置
|
6月前
|
开发工具 iOS开发 开发者
「Mac畅玩鸿蒙与硬件2」鸿蒙开发环境配置篇2 - 在Mac上安装DevEco Studio
本篇将专注于如何在 Mac 上安装鸿蒙开发工具 DevEco Studio,确保开发环境能够顺利搭建。完成安装后,可以正式开始鸿蒙应用的开发工作。
314 1
「Mac畅玩鸿蒙与硬件2」鸿蒙开发环境配置篇2 - 在Mac上安装DevEco Studio
|
8月前
|
Oracle Java 关系型数据库
Mac电脑上安装和配置Flutter开发环境
Mac电脑上安装和配置Flutter开发环境
226 59
|
7月前
|
存储 负载均衡 监控
dubbo学习一:zookeeper与dubbo的关系,下载安装启动zookeeper(解决启动中报错)
这篇文章是关于Apache Dubbo框架与Zookeeper的关系,以及如何下载、安装和启动Zookeeper的教程,包括解决启动过程中可能遇到的报错问题。
264 3
dubbo学习一:zookeeper与dubbo的关系,下载安装启动zookeeper(解决启动中报错)
|
7月前
|
机器学习/深度学习 Python
【10月更文挑战第5天】「Mac上学Python 6」入门篇6 - 安装与使用Anaconda
本篇将详细介绍如何在Mac系统上安装和配置Anaconda,如何创建虚拟环境,并学习如何使用 `pip` 和 `conda` 管理Python包,直到成功运行第一个Python程序。通过本篇,您将学会如何高效地使用Anaconda创建和管理虚拟环境,并使用Python开发。
238 4
【10月更文挑战第5天】「Mac上学Python 6」入门篇6 - 安装与使用Anaconda
|
7月前
|
IDE 开发工具 iOS开发
【10月更文挑战第3天】「Mac上学Python 3」入门篇3 - 安装Python与开发环境配置
本篇将详细介绍如何在Mac系统上安装Python,并配置Python开发环境。内容涵盖Python的安装、pip包管理工具的配置与国内镜像源替换、安装与配置PyCharm开发工具,以及通过PyCharm编写并运行第一个Python程序。通过本篇的学习,用户将完成Python开发环境的搭建,为后续的Python编程工作打下基础。
543 2
【10月更文挑战第3天】「Mac上学Python 3」入门篇3 - 安装Python与开发环境配置