1

I just switched to a M1 MacBook Air and I'm having trouble with Homebrew. The installation went fine I think, and then I added it to my path with the given commands:

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)"

I also did brew install cunit and then when I typed brew list CUnit was listed there so I'm assuming the brew install of cunit worked.

But when I run my C test code this is what I get:

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

I have been sitting with this for three days, called Apple support, searched every page related to this and still can't find a solution that works.

Has anyone had the same problem? PLEASE help

nattap
  • 11
  • 1
  • 2

1 Answers1

6

Homebrew installs into /opt/homebrew by default on M1 Macs, and no longer links into /usr/local by default (to prevent clashes with Rosetta library installs). This means that include files and libraries can't be found without explicitly telling the compiler/linker where your Homebrew packages are installed.

The easiest way of doing this is by setting the CPATH environmental variable before compiling:

export CPATH=/opt/homebrew/include

Add the above line to your shell profile (.zprofile for zsh, or .bash_profile for bash) and it will be used in all future compilations.

For dependencies which also require shared libraries, you will need to also signpost the location of Homebrew's new lib path:

export LIBRARY_PATH=/opt/homebrew/lib
Daniel Jones
  • 615
  • 5
  • 17