The error happens when running g++(gcc@12) with -fsanitize=address
option.
$ g++-12 --std=c++20 -g -fsanitize=address ./main.cpp -o a.out
ld: library not found for -lasan
collect2: error: ld returned 1 exit status
I reinstalled gcc@12 and nothing changed.
I couldn't find libasan.dylib for gcc@12.
$ find /usr/local -name "*asan*"
/usr/local/Cellar/llvm/17.0.6_1/lib/clang/17/include/sanitizer/asan_interface.h
/usr/local/Cellar/llvm/17.0.6_1/lib/clang/17/include/sanitizer/hwasan_interface.h
/usr/local/Cellar/llvm/17.0.6_1/lib/clang/17/lib/darwin/libclang_rt.asan_abi_osx.a
/usr/local/Cellar/llvm/17.0.6_1/lib/clang/17/lib/darwin/libclang_rt.asan_osx_dynamic.dylib
/usr/local/Cellar/llvm/17.0.6_1/lib/clang/17/share/asan_ignorelist.txt
/usr/local/Cellar/gcc/13.2.0/lib/gcc/current/gcc/x86_64-apple-darwin23/13/plugin/include/asan.h
/usr/local/Cellar/gcc@12/12.3.0/lib/gcc/12/gcc/x86_64-apple-darwin23/12/plugin/include/asan.h
/usr/local/Cellar/gcc@9/9.5.0/lib/gcc/9/libasan_preinit.o
/usr/local/Cellar/gcc@9/9.5.0/lib/gcc/9/gcc/x86_64-apple-darwin21/9.5.0/include/sanitizer/asan_interface.h
/usr/local/Cellar/gcc@9/9.5.0/lib/gcc/9/gcc/x86_64-apple-darwin21/9.5.0/plugin/include/asan.h
/usr/local/Cellar/gcc@9/9.5.0/lib/gcc/9/libasan.dylib
/usr/local/Cellar/gcc@9/9.5.0/lib/gcc/9/libasan.5.dylib
$ find /Library/Developer/CommandLineTools -name "*asan*"
/Library/Developer/CommandLineTools/usr/lib/clang/13.1.6/include/sanitizer/asan_interface.h
...
/Library/Developer/CommandLineTools/usr/lib/clang/15.0.0/lib/darwin/libasan.dylib
/Library/Developer/CommandLineTools/usr/lib/clang/15.0.0/lib/darwin/libclang_rt.asan_osx_dynamic.dylib
/Library/Developer/CommandLineTools/usr/lib/clang/15.0.0/lib/darwin/libclang_rt.asan_ios_dynamic.dylib
/Library/Developer/CommandLineTools/usr/lib/clang/15.0.0/lib/darwin/libclang_rt.asan_watchossim_dynamic.dylib
/Library/Developer/CommandLineTools/usr/lib/clang/15.0.0/lib/darwin/libclang_rt.asan_tvossim_dynamic.dylib
/Library/Developer/CommandLineTools/usr/lib/clang/15.0.0/share/asan_ignorelist.txt
/Library/Developer/CommandLineTools/SDKs/MacOSX14.2.sdk/usr/lib/libSystem_asan.tbd
/Library/Developer/CommandLineTools/SDKs/MacOSX14.2.sdk/usr/lib/libSystem.B_asan.tbd
I checked AddressSanitizer's documentation and gcc seems supporting AddressSanitizer in x86_64 OS X.
I checked the formula of gcc@12 and I wonder if it is ok the args don't contain --enable-libsanitizer
.
Is there something I can try to fix the error?
The sanitizer seems no longer supported in x86_64 macOS (since Ventura).
https://github.com/orgs/Homebrew/discussions/3384#discussioncomment-6264292