Snaipe / Criterion

A cross-platform C and C++ unit testing framework for the 21st century
MIT License
1.93k stars 175 forks source link

Installing with homebrew not work on macOs #513

Closed ghost closed 2 weeks ago

ghost commented 7 months ago

Compile a sample test give this error:

Apple clang version 14.0.0 (clang-1400.0.29.202)
Target: arm64-apple-darwin21.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
 "/Library/Developer/CommandLineTools/usr/bin/clang" -cc1 -triple arm64-apple-macosx12.0.0 -Wundef-prefix=TARGET_OS_ -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -Werror=implicit-function-declaration -emit-obj -mrelax-all --mrelax-relocations -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name m.c -mrelocation-model pic -pic-level 2 -mframe-pointer=non-leaf -fno-strict-return -fno-rounding-math -funwind-tables=2 -fobjc-msgsend-selector-stubs -target-sdk-version=13.1 -fvisibility-inlines-hidden-static-local-var -target-cpu apple-m1 -target-feature +v8.5a -target-feature +fp-armv8 -target-feature +neon -target-feature +crc -target-feature +crypto -target-feature +dotprod -target-feature +fp16fml -target-feature +ras -target-feature +lse -target-feature +rdm -target-feature +rcpc -target-feature +zcm -target-feature +zcz -target-feature +fullfp16 -target-feature +sm4 -target-feature +sha3 -target-feature +sha2 -target-feature +aes -target-abi darwinpcs -fallow-half-arguments-and-returns -debugger-tuning=lldb -target-linker-version 820.1 -v -resource-dir /Library/Developer/CommandLineTools/usr/lib/clang/14.0.0 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/opt/homebrew/include -I/usr/local/include -internal-isystem /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/local/include -internal-isystem /Library/Developer/CommandLineTools/usr/lib/clang/14.0.0/include -internal-externc-isystem /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include -internal-externc-isystem /Library/Developer/CommandLineTools/usr/include -Wno-reorder-init-list -Wno-implicit-int-float-conversion -Wno-c99-designator -Wno-final-dtor-non-final-class -Wno-extra-semi-stmt -Wno-misleading-indentation -Wno-quoted-include-in-framework-header -Wno-implicit-fallthrough -Wno-enum-enum-conversion -Wno-enum-float-conversion -Wno-elaborated-enum-base -Wno-reserved-identifier -Wno-gnu-folding-constant -Wno-cast-function-type -Wno-bitwise-instead-of-logical -fdebug-compilation-dir=/Users/lorenzo -ferror-limit 19 -stack-protector 1 -fstack-check -mdarwin-stkchk-strong-link -fblocks -fencode-extended-block-signature -fregister-global-dtors-with-atexit -fgnuc-version=4.2.1 -fmax-type-align=16 -fcommon -fcolor-diagnostics -clang-vendor-feature=+messageToSelfInClassMethodIdReturnType -clang-vendor-feature=+disableInferNewAvailabilityFromInit -clang-vendor-feature=+disableNonDependentMemberExprInCurrentInstantiation -fno-odr-hash-protocols -clang-vendor-feature=+enableAggressiveVLAFolding -clang-vendor-feature=+revert09abecef7bbf -clang-vendor-feature=+thisNoAlignAttr -clang-vendor-feature=+thisNoNullAttr -mllvm -disable-aligned-alloc-awareness=1 -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /var/folders/mk/8hc9rhb512q458j43wytr9s00000gn/T/m-383bf5.o -x c m.c
clang -cc1 version 14.0.0 (clang-1400.0.29.202) default target arm64-apple-darwin21.6.0
ignoring nonexistent directory "/usr/local/include"
ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/local/include"
ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/Library/Frameworks"
#include "..." search starts here:
#include <...> search starts here:
 /opt/homebrew/include
 /Library/Developer/CommandLineTools/usr/lib/clang/14.0.0/include
 /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include
 /Library/Developer/CommandLineTools/usr/include
 /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks (framework directory)
End of search list.
 "/Library/Developer/CommandLineTools/usr/bin/ld" -demangle -lto_library /Library/Developer/CommandLineTools/usr/lib/libLTO.dylib -no_deduplicate -dynamic -arch arm64 -platform_version macos 12.0.0 13.1 -syslibroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -o m -L/opt/homebrew/lib -L/usr/local/lib /var/folders/mk/8hc9rhb512q458j43wytr9s00000gn/T/m-383bf5.o -lSystem /Library/Developer/CommandLineTools/usr/lib/clang/14.0.0/lib/darwin/libclang_rt.osx.a
Undefined symbols for architecture arm64:
  "_cr_asprintf", referenced from:
      _x_y_impl in m-383bf5.o
  "_cr_asprintf_free", referenced from:
      _x_y_impl in m-383bf5.o
  "_cr_translate_assert_msg", referenced from:
      _x_y_impl in m-383bf5.o
  "_cri_asserts_passed_incr", referenced from:
      _x_y_impl in m-383bf5.o
  "_criterion_abort_test", referenced from:
      _x_y_impl in m-383bf5.o
  "_criterion_internal_test_main", referenced from:
      _x_y_jmp in m-383bf5.o
  "_criterion_internal_test_setup", referenced from:
      _x_y_jmp in m-383bf5.o
  "_criterion_internal_test_teardown", referenced from:
      _x_y_jmp in m-383bf5.o
  "_criterion_options", referenced from:
      _x_y_impl in m-383bf5.o
  "_criterion_send_assert", referenced from:
      _x_y_impl in m-383bf5.o
  "_main", referenced from:
     implicit entry/start for main executable
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

This is the sample:

#include <criterion/criterion.h>

Test(x,y){
    return(0)
}
margce commented 7 months ago

Same issue here, I installed criterion using brew on my M1 macbook pro. When trying to compile a simple file I get

gcc -o test simple.c -lcriterion
simple.c:1:10: fatal error: 'criterion/criterion.h' file not found
#include <criterion/criterion.h>
         ^~~~~~~~~~~~~~~~~~~~~~~
1 error generated.

So in order to compile I have to specify the location of both the include directory and lib location using

gcc -o simple -I/opt/homebrew/Cellar/criterion/2.4.1_3/include simple.c -L/opt/homebrew/Cellar/criterion/2.4.1_3/lib -lcriterion
./simple
[----] simple.c:4: Assertion Failed
[----]   
[----]   The expression 0 is false.
[----]   
[FAIL] misc::failing: (0.00s)
[====] Synthesis: Tested: 2 | Passing: 1 | Failing: 1 | Crashing: 0

I'm looking for a way to for Apple clang to directly fetch the libraries and includes from homebrew but haven't found the correct way to do it yet. But at least with that you should be able to compile

PieterT2000 commented 6 months ago

See this SO post for more info. https://stackoverflow.com/questions/74912616/criterion-c-header-not-found-on-macos/77366984#77366984. Instead of passing include and lib folders of the Criterion tap, you can pass the HomeBrew's global include and lib folders as per the linked answer.

aleshasuqa commented 5 months ago

Same issue here, I installed criterion using brew on my M1 macbook pro. When trying to compile a simple file I get

gcc -o test simple.c -lcriterion
simple.c:1:10: fatal error: 'criterion/criterion.h' file not found
#include <criterion/criterion.h>
         ^~~~~~~~~~~~~~~~~~~~~~~
1 error generated.

So in order to compile I have to specify the location of both the include directory and lib location using

gcc -o simple -I/opt/homebrew/Cellar/criterion/2.4.1_3/include simple.c -L/opt/homebrew/Cellar/criterion/2.4.1_3/lib -lcriterion
./simple
[----] simple.c:4: Assertion Failed
[----]   
[----]   The expression 0 is false.
[----]   
[FAIL] misc::failing: (0.00s)
[====] Synthesis: Tested: 2 | Passing: 1 | Failing: 1 | Crashing: 0

I'm looking for a way to for Apple clang to directly fetch the libraries and includes from homebrew but haven't found the correct way to do it yet. But at least with that you should be able to compile

Adding homebrew include and lib to CPATH and PATH_LIBRARY worked for me export CPATH=/opt/homebrew/include export LIBRARY_PATH=/opt/homebrew/lib

jcsahnwaldt commented 4 months ago

I think this can be closed. As explained by others, setting the include and library paths fixes the problem.

chenrui333 commented 3 months ago

Also you can find some basic aspirations on the homebrew example. https://github.com/Homebrew/homebrew-core/blob/master/Formula/c/criterion.rb#L36-L47