macbook M1芯片 arm64 安装部分软件出错的解决方案

M1芯片默认使用的arm64架构,可以使用如下命令查看:uname -a 

 

当我安装了brew(https://www.cnblogs.com/rxbook/p/16377843.html),

再使用brew安装kafka、librdkafka、php-rdkafka 的时候,都是没问题的,参考 https://www.cnblogs.com/rxbook/p/10877784.html

但是使用php -m 查看是否安装成功的时候 却出错了:

Warning: PHP Startup: Unable to load dynamic library 'rdkafka.so' (tried: /Applications/MxSrvs/bin/php/ext/rdkafka.so (dlopen(/Applications/MxSrvs/bin/php/ext/rdkafka.so, 0x0009): tried: '/Applications/MxSrvs/bin/php/ext/rdkafka.so' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64'))), /Applications/MxSrvs/bin/php/ext/rdkafka.so.so (dlopen(/Applications/MxSrvs/bin/php/ext/rdkafka.so.so, 0x0009): tried: '/Applications/MxSrvs/bin/php/ext/rdkafka.so.so' (no such file))) in Unknown on line 0

大致意思就是已经安装了arm64架构的,但是需要x86_64架构的。折腾了五六个小时,总算找到了解决方案,必须得记录下来,以备后用:

https://blog.csdn.net/qq_41017902/article/details/123458089

在终端中执行命令arch -x86_64 zsh来切换架构,切换之后,再查看 uname -a :

然后再重新安装x86的brew、kafka、librdkafka、php-rdkafka

参考:http://t.zoukankan.com/jinzhao-p-15662791.html

X86 HomeBrew

$ arch -x86_64 zsh

$ cd /usr/local && mkdir homebrew

$ curl -L https://github.com/Homebrew/brew/tarball/master | tar xz --strip 1 -C homebrew

Alias快捷别名(vim ~/.zshrc)

alias ibrew='arch -x86_64 /usr/local/bin/brew'
alias izsh='arch -x86_64 zsh'
alias azsh='arch -arm64e zsh'

 

完了之后再重复上面的安装步骤就好了。

# 安装 kafka

 ibrew install kafka


# 安装librdkafka git clone https://github.com/edenhill/librdkafka.git cd librdkafka ./configure make make install # 安装php-rdkafka git clone https://github.com/arnaud-lb/php-rdkafka.git cd php-rdkafka /Applications/MxSrvs/bin/php/bin/phpize ./configure --with-php-config=/Applications/MxSrvs/bin/php/bin/php-config make && make install cp /Applications/MxSrvs/bin/php/lib/php/extensions/no-debug-non-zts-20180731/rdkafka.so /Applications/MxSrvs/bin/php/ext/ # 在php.ini加入如下信息 extension=rdkafka.so

 

 

posted @ 2022-06-22 18:22  浮尘微光  阅读(5026)  评论(0编辑  收藏  举报