Homebrew Mac M1 找不到安装

1 c installation homebrew cunit homebrew-cask

我刚刚换用 M1 MacBook Air,但在使用 Homebrew 时遇到了问题。我认为安装很顺利,然后我使用给定的命令将其添加到我的路径中:

Run these two commands in your terminal to add Homebrew to your PATH:

    echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/xxx/.zprofile
    eval "$(/opt/homebrew/bin/brew shellenv)"
Run Code Online (Sandbox Code Playgroud)

我也brew install cunit这样做了,然后当我输入brew listCUnit 时,它就列在那里,所以我假设 cunit 的brew 安装工作正常。

但是当我运行我的 C 测试代码时,我得到的是:

test/test.c:3:10: fatal error: 'CUnit/Basic.h' file not found
#include <CUnit/Basic.h>
         ^~~~~~~~~~~~~~~
1 error generated.
make: *** [test_compile] Error 1
Run Code Online (Sandbox Code Playgroud)

我已经解决这个问题三天了,打电话给苹果支持,搜索了与此相关的每个页面,但仍然找不到有效的解决方案。

有人遇到过同样的问题吗?请帮忙

Dan*_*nes 7

Homebrew在 M1 Mac 上默认安装到 /opt/homebrew,并且默认情况下不再链接到/usr/local(以防止与 Rosetta 库安装发生冲突)。这意味着如果不明确告诉编译器/链接器 Homebrew 软件包的安装位置,则无法找到包含文件和库。

最简单的方法是在编译之前设置CPATH环境变量:

export CPATH=/opt/homebrew/include
Run Code Online (Sandbox Code Playgroud)

将以上行添加到您的 shell 配置文件(.zprofile对于 zsh 或.bash_profilebash),它将在以后的所有编译中使用。

对于也需要共享库的依赖项,您还需要标记 Homebrew 新lib路径的位置:

export LIBRARY_PATH=/opt/homebrew/lib
Run Code Online (Sandbox Code Playgroud)