“致命错误:找不到‘EXTERN.h’文件"安装 Perl 模块时 [英] "Fatal error: 'EXTERN.h' file not found" while installing Perl modules

查看:52
本文介绍了“致命错误:找不到‘EXTERN.h’文件"安装 Perl 模块时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在尝试安装 JSON::XS 或 YAML::XS 等 Perl 模块时,我收到相同的错误:

While trying to install Perl modules like JSON::XS or YAML::XS, i receive the same error:

XS.xs:1:10: 致命错误:找不到EXTERN.h"文件

XS.xs:1:10: fatal error: 'EXTERN.h' file not found

我使用 MacBook,xCode 是最新的,其他所有可以帮助的东西也是最新的.

I use MacBook, xCode is up to date, everything else that could help is up to date too.

推荐答案

自 OS X El Capitan 以来,Apple 推出了 系统完整性保护 限制写入/usr/lib/usr/bin 和其他敏感目录(甚至是 root 或 sudo 用户),这些目录由与操作系统捆绑的 Perl 安装使用.这可能会导致安装新模块以及尝试安装 XS 模块(链接到外部 C 库的模块)时出现问题.

Since OS X El Capitan, Apple introduced System Integrity Protection which restricts writing to /usr/lib /usr/bin and other sensitive directories (even to root or sudo user) that are used by the installation of Perl bundled with the Operating System. This can cause issues when it comes to installing new modules and also if trying to install XS modules ( those linked to external C libraries ).

因此,您不应将默认的 Perl 安装视为工作开发环境,尤其是在安装自定义模块时.

For this reason you should not consider the default Perl installation as a working development environment, especially if you are installing custom modules.

查看 PM 上的这个主题 和其他人.自从 El-Capitan 之前设法通过从 tarball 手动构建并添加一些参数或环境变量来设置路径来解决这个问题,我相信最好保留系统 Perl 的使用,但这不是要走的路.这会导致您的环境难以构建,但也会变得脆弱且容易受到操作系统更新的影响,这些更新可能会以多种不同的方式破坏事物.

Check out this thread on PM and others. I had since El-Capitan managed to solve this before by manually building from tarball and adding a few params or environment variables to set the paths believing that it would be best to retain use of the system Perl but this is not the way to go. This makes your environment difficult to build but also brittle and sensitive to OS updates that may either break things in many different ways.

最佳实践似乎是从使用 brew install perl 的 Perl 开始并在此环境中工作,记住按照安装程序的指示设置 bash_profile.

The best practice seems to be starting with a Perl using brew install perl and work in this environment, remembering to setup your bash_profile as directed by the installer.

还值得记住做一个brew link perl.如果您收到有关这种破坏看起来像系统 Perl 库的警告,请不要担心 - 这些可能是您在顶部安装的模块,并且可以减少链接这些模块的麻烦.如果您有顾虑,请记下哪些模块安装将被清除,并在您的环境配置好后重新安装它们(即您的模块安装程序方法是使用 cpanm 配置的或坚持使用旧的 perl -MCPAN -e shell etc)

Also worth remembering to do a brew link perl. If you receive warnings about this clobbering what looks like system Perl libraries don't worry - these are likely modules that were installed by you over the top and it will cause you less trouble to link over these. If you have concerns, make a note of which module installs will be cleared and re-install them once your environment is configured ( ie your module installer approach is configured using cpanm or sticking with the old perl -MCPAN -e shell etc)

这个来自 brew 的新 Perl 设置消除了继续运行 sudo 的需要,这增加了另一层可能会出错的事情,因为环境变量没有跟进和权限冲突出现等.

This new Perl setup from brew eliminates the need to continuing running sudo which adds another layer of things that can go wrong as environment variables don't follow through and permission conflicts arise etc.

最后,为了简化包/模块安装,我建议执行 brew install cpanminus.如果您之前已经安装了它,您可以通过执行 brew 重新安装 cpanminus

Finally to simplify package/module installation I suggest doing a brew install cpanminus. If you had previously already installed this, you can ensure the paths etc are configured by doing a brew reinstall cpanminus

如果您想更进一步,那么您也可以安装 perlbrew,这将使您能够以用户身份运行多个版本的 Perl,并使用自己的库和模块配置它们,这在以下情况下非常有用与您的生产环境保持一致以进行测试等.

If you want to take it another step further then you can install perlbrew as well which will give you the ability to run multiple versions of Perl as your user and configure these with their own libs and modules which can be very useful particularly if aligning with your production environment for testing etc.

如果从系统 Perl 迁移到这种方法,您可能面临的一个问题是需要处理使用 sudo 安装东西的任何后遗症.值得花一点时间来正确设置所有这些,您未来的问题将大大减少,并且您不会有那种烦人的感觉,即您不想改变任何东西,因为害怕一切都会破裂.

One problem you may face if moving from system Perl to this kind of approach is needing to deal with any hangovers from installing things with sudo. It wis worth taking a little time to get all this set up right though and your issues going forward will be greatly reduced and you won't be left with that nagging feeling that you don't want to change anything for fear of it all breaking.

我还遇到了一个 Perl 博客文章,建议修复 Mojave 上 perlbrew 的 XS 问题

这个 Gist 描述了更新您的 cpan shell 安装根目录,尽管这不是必需的除非您的 cpan 在执行上述步骤后卡在旧配置中.

This Gist described updating your cpan shell install root though this shouldn't be necessary unless your cpan is stuck in an old config after taking steps above.

我也在 PerlMonks

这篇关于“致命错误:找不到‘EXTERN.h’文件"安装 Perl 模块时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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