为什么Homebrew创建了一个/usr/local/opt目录,我应该使用它吗? [英] Why is there a /usr/local/opt directory created by Homebrew and should I use it?

查看:907
本文介绍了为什么Homebrew创建了一个/usr/local/opt目录,我应该使用它吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用自制软件方面很陌生,我试图弄清楚在我自己的项目中使用某些库(例如,boost,gsl,openblas)的工作方式.

I am quite new at using homebrew and I am trying to figure out how it works to use some libraries (boost, gsl, openblas for example) in my own project.

我知道每个公式都是由Homebrew在/usr/local/Cellar/中安装的,然后在usr/local/bin,usr/local/lib,usr/local/include中进行符号链接,所以似乎除外-only公式,因此不会与操作系统已安装的库混淆(请参阅了解自制程序和仅桶依赖项).但是我发现每个公式也都链接到/usr/local/opt目录.

I have understood that each formula is installed by Homebrew in /usr/local/Cellar/ and then symlinked in usr/local/bin, usr/local/lib, usr/local/include, so it seems, excepts for keg-only formulas so it does not mess with already installed libraries by the OS (cf. Understand homebrew and keg-only dependencies for example). But I found out that every formula is also linked to a /usr/local/opt directory.

所以我的问题是,为什么存在这个/usr/local/opt目录(有点多余),使用公式(usr/local/Cellar或usr/local/或usr)必须使用什么路径?/local/opt基本上)?

So my question is why is there this /usr/local/opt directory (it is kind of redundant), and what path do I have to use for using formulas (usr/local/Cellar or usr/local/ or usr/local/opt basically) ?

推荐答案

它为公式的内容提供了一个路径,该路径在版本升级中不会更改.

It provides a path for a formula's contents that does not change across version upgrades.

请考虑以下情形:假设您使用Homebrew构建libfoo.dylib.它是2.0.0版,因此它位于/usr/local/Cellar/libfoo/2.0.0/lib/libfoo.dylib.您要从正在构建的另一个程序链接到它,因此您将-L/usr/local/Cellar/libfoo/2.0.0/lib -lfoo传递给gcc.您的程序会编译.稍后,您升级到libfoo 2.0.1并删除v2.0.0.现在/usr/local/Cellar/libfoo/2.0.0/lib/libfoo.dylib不再存在,并且您的程序不再运行,因为它无法动态加载libfoo.

Consider this scenario: Say you build libfoo.dylib with Homebrew. It is version 2.0.0, and so it lives at /usr/local/Cellar/libfoo/2.0.0/lib/libfoo.dylib. You want to link to it from another program you are building, so you pass -L/usr/local/Cellar/libfoo/2.0.0/lib -lfoo to gcc. Your program compiles. Later on, you upgrade to libfoo 2.0.1 and remove v2.0.0. Now /usr/local/Cellar/libfoo/2.0.0/lib/libfoo.dylib no longer exists, and your program no longer runs, because it can't dynamically load libfoo.

没关系.在/usr/local/lib/libfoo.dylib中也可以使用libfoo.dylib.这是最新版本的libfoo的符号链接,因此应始终存在.因此,您将-L/usr/local/lib -lfoo传递给程序并进行编译.稍后,您升级到libfoo 2.0.1.没问题,因为/usr/local/lib/libfoo.dylib仍然存在并指向v2.0.1副本.

That's okay. libfoo.dylib is also available at /usr/local/lib/libfoo.dylib. It's a symlink to the latest version of libfoo, so it should always be present. So you pass -L/usr/local/lib -lfoo to your program and compile it. Later you upgrade to libfoo 2.0.1. No problem, because /usr/local/lib/libfoo.dylib is still present and points to the v2.0.1 copy.

那太好了,而Homebrew仅仅在那个系统中存在了一段时间.问题是,某些公式是仅插入"的,因此它们没有与/usr/local链接. (通常它们是仅桶装的,因为它们会遮盖OS X附带的库的一个版本,而取代OS X库可能会导致问题.)假设您要链接到该库的仅桶装的版本.它不是从/usr/local/lib符号链接的,因此您必须提供安装在/usr/local/Cellar中的版本的完整路径,这使您回到上面列出的第一个问题.

That's great, and Homebrew existed with just that system for a while. The problem is, some formula are "keg-only", so they are not symlinked from /usr/local. (Generally they are keg-only because they shadow a version of a library that ships with OS X, and superseding OS X libraries can cause problems.) Say you want to link to a keg-only version of the library. It's not symlinked from /usr/local/lib, so you have to give the full path to the version installed in /usr/local/Cellar, which is brings you back to the first problem listed above.

/usr/local/opt解决了此问题.它为所有版本的 all 公式提供了符号链接,无论它们是否仅是桶.现在,当您要编译程序时,可以使用-L/usr/local/opt/libfoo/lib -lfoo,并且程序将链接到最新版本的libfoo,即使您对其进行了升级,甚至仅是桶也是如此.

/usr/local/opt solves this problem. It provides a place for the current version of all formulae to be symlinked, regardless of whether they are keg-only or not. Now, when you want to compile your program, you can use -L/usr/local/opt/libfoo/lib -lfoo, and your program will link to the latest version of libfoo, even if you upgrade it and even if it is keg-only.

这篇关于为什么Homebrew创建了一个/usr/local/opt目录,我应该使用它吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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