Hi Nan, on 2019/12/26 下午4:48, Nan Xiao wrote: > Hi gcc community, > > Greetings from me! > > I am using Void Linux, and want to use sanitizers. Using clang to > compile code, it is OK: > > $ clang -std=c11 -fsanitize=address test.c > $ > > While gcc reports following errors: > > $ gcc -std=c11 -fsanitize=address test.c > /usr/bin/ld: cannot find libasan_preinit.o: No such file or directory > /usr/bin/ld: cannot find -lasan > collect2: error: ld returned 1 exit status > May I suggest you checking your gcc whether disabled libsanitizer support? GCC configuration allows you to build one gcc without libsanitizer support with --disable-libsanitizer. "gcc -v" can show the configuration options. > I check the program compiled with clang: > > $ ldd a.out > linux-vdso.so.1 (0x00007fffd858a000) > libpthread.so.0 => /usr/lib/libpthread.so.0 (0x00007fc1659b8000) > librt.so.1 => /usr/lib/librt.so.1 (0x00007fc1659ad000) > libm.so.6 => /usr/lib/libm.so.6 (0x00007fc165868000) > libdl.so.2 => /usr/lib/libdl.so.2 (0x00007fc165863000) > libgcc_s.so.1 => /usr/lib/libgcc_s.so.1 (0x00007fc165849000) > libc.so.6 => /usr/lib/libc.so.6 (0x00007fc165686000) > /lib64/ld-linux-x86-64.so.2 => /lib/ld-linux-x86-64.so.2 (0x00007fc1659e0000) > See https://github.com/google/sanitizers/wiki/AddressSanitizerAsDso I guess your clang was configured as static asan library by default. So it's linked with static library, you can't find libasan.so with ldd. > No asan library is required. > It requires static library. By the way, for gcc you can link with static library via gcc option -static-libasan. BR, Kewen