2

I have the requirement to install Criterion (which is a testing framework for C) on my laptop running macOS. I use Homebrew daily so I thought it will be be easy to just run the brew command:

brew install criterion

But, every time I try to run a C file with the criterion header with GCC or CLANG, it just can't find Criterion, although it is installed. (I use the simple sample from the official Criterion repo)

#include <criterion/criterion.h>

Test(misc, failing) {
    cr_assert(0);
}

Test(misc, passing) {
    cr_assert(1);
}
$ gcc -o test test.c -lcriterion
test.c:1:10: fatal error: 'criterion/criterion.h' file not found
#include <criterion/criterion.h>
         ^~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
$ brew install criterion
Warning: criterion 2.4.1_1 is already installed and up-to-date.
To reinstall 2.4.1_1, run:
  brew reinstall criterion

I'm struggling with that for almost 2 days and I'm out of ideas... I even tried to install gcc via Homebrew but it doesn't seem to work either

$ /opt/homebrew/Cellar/gcc/12.2.0/bin/gcc-12 -o test test.c -lcriterion
test.c:1:10: fatal error: criterion/criterion.h: No such file or directory
    1 | #include <criterion/criterion.h>
      |          ^~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.

I use the Apple clang version 14.0.0 for gcc and the homebrew gcc uses gcc 12.2.0. I run a MacBook Air M1 2020 with Ventura 13.1 (22C65)

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
drawbu
  • 81
  • 6
  • Where does `brew` install its packages? I assume it's in a non-standard location, so you have to add flags to tell the compiler where to find header files, and also to the linker to tell it where to find the libraries? – Some programmer dude Dec 25 '22 at 09:57
  • 2
    You need to provide the path of the header files (criterion.h) to gcc using -I flag. E.g. `gcc -o test test.c -lcriterion -I /usr/include/` if `criterion.h` is in `/usr/include/criterion` directory – Gaurav Pathak Dec 25 '22 at 09:57
  • 2
    I'd guess it's in /opt/homebrew/include, and you'll probably have to specify `-I/opt/homebrew/include -L/opt/homebrew/lib`. I don't know homebrew well enough to know if it's supposed to set that up for you automatically e.g. in the INCLUDE and LIBS environment vars. – Rup Dec 25 '22 at 09:57
  • "I use the Apple clang version 14.0.0 for gcc and the homebrew gcc uses gcc 12.2.0." - why different versions? You're probably OK with C but that can be painful with C++. – Rup Dec 25 '22 at 09:59
  • add `-I/usr/local/Cellar` to build process. check `brew ls --verbose criterion`. – Marek R Dec 25 '22 at 10:13
  • Thanks! This was that simple... just needed to specified the path of the header files like said @Rup... thanks everyone, and merry christmas! – drawbu Dec 25 '22 at 10:15

0 Answers0