EDIT . If its TL; DR, just skip from the bottom. Its where I ask: How to set up an autotools project to use a static library?
I work with several open source libraries, and I try to run their test suite under Clang sanitizers. To work under Clang disinfectants, we need to (1) specify some parameters and (2) link the static libraries from Clang Compiler-RT as needed. Note: There are no dynamic libraries or shared objects.
Setting parameters is very simple:
export DYLD_FALLBACK_LIBRARY_PATH=/usr/local/lib/clang/3.3/lib/darwin/ export CC=/usr/local/bin/clang export CXX=/usr/local/bin/clang++ export CFLAGS="-g3 -fsanitize=address -fsanitize=undefined" export CXXFLAGS="-g3 -fsanitize=address -fsanitize=undefined -fno-sanitize=vptr" ./configure
However, this will lead to some warnings about archives (when starting AR ) and link errors (when starting LD ) with undefined characters. The message will look like:
libjpeg.a(jmemmgr.o): In function `do_sarray_io': /home/jwalton/jpeg-6b/jmemmgr.c:695: undefined reference to `__ubsan_handle_type_mismatch' /home/jwalton/jpeg-6b/jmemmgr.c:695: undefined reference to `__ubsan_handle_type_mismatch' /home/jwalton/jpeg-6b/jmemmgr.c:696: undefined reference to `__ubsan_handle_type_mismatch'
I know the libraries that need to be linked. For the sanitizers that I use, they are libclang_rt.asan_osx.a and libclang_rt.ubsan_osx.a (or libclang_rt.full-x86_64.a and libclang_rt.ubsan-x86_64.a on Linux).
To provide libraries, I then export the following. Note: these are LIBS , not LDLIBS , as expected by most other make related tools.
export LIBS="/usr/local/lib/clang/3.3/lib/darwin/libclang_rt.asan_osx.a \ /usr/local/lib/clang/3.3/lib/darwin/libclang_rt.ubsan_osx.a"
The result is a configure problem:
configure: error: cannot run C compiled programs. If you meant to cross compile, use `--host'. ...
Looking at config.log , it looks like there are two problems. Firstly, the path is blocked by a change from /usr/local/... to /Users/jwalton/... And secondly, the file name is blocked by moving from static lib to dynamic lib:
configure:3346: ./conftest dyld: Library not loaded: /Users/jwalton/clang-llvm/llvm-3.3.src/Release+Asserts/lib/clang/3.3/lib/darwin/libclang_rt.asan_osx_dynamic.dylib Referenced from: /Users/jwalton/libpng-1.6.7/./conftest Reason: image not found
In another attempt, I tried using LDFLAGS :
export LDFLAGS="-L/usr/local/lib/clang/3.3/lib/darwin/" export LIBS="libclang_rt.asan_osx.a libclang_rt.ubsan_osx.a"
This results in a similar error:
configure: error: in `/Users/jwalton/libpng-1.6.7': configure: error: C compiler cannot create executables
And config.log :
configure:3209: /usr/local/bin/clang -g3 -fsanitize=address -fsanitize=undefined -L/usr/local/lib/clang/3.3/lib/darwin/ conftest.c libclang_rt.asan_osx.a libclang_rt.ubsan_osx.a >&5 clang: error: no such file or directory: 'libclang_rt.asan_osx.a' clang: error: no such file or directory: 'libclang_rt.ubsan_osx.a'
And removing the lib and .a from LIBS results in:
configure:3209: /usr/local/bin/clang -g3 -fsanitize=address -fsanitize=undefined -L/usr/local/lib/clang/3.3/lib/darwin/ conftest.c clang_rt.asan_osx clang_rt.ubsan_osx >&5 clang: error: no such file or directory: 'clang_rt.asan_osx' clang: error: no such file or directory: 'clang_rt.ubsan_osx'
And adding -l to LIBS results in:
configure:3335: /usr/local/bin/clang -o conftest -g3 -fsanitize=address -fsanitize=undefined -L/usr/local/lib/clang/3.3/lib/darwin/ conftest.c -lclang_rt.asan_osx -lclang_rt.ubsan_osx >&5 configure:3339: $? = 0 configure:3346: ./conftest dyld: could not load inserted library: /Users/jwalton/libpng-1.6.7/./conftest ./configure: line 3348: 38224 Trace/BPT trap: 5 ./conftest$ac_cv_exeext
Finally, the -l argument is valid:
$ ls /usr/local/lib/clang/3.3/lib/darwin/ libclang_rt.10.4.a libclang_rt.ios.a libclang_rt.asan_osx.a libclang_rt.osx.a libclang_rt.asan_osx_dynamic.dylib libclang_rt.profile_ios.a libclang_rt.cc_kext.a libclang_rt.profile_osx.a libclang_rt.cc_kext_ios5.a libclang_rt.ubsan_osx.a libclang_rt.eprintf.a
After the whole background: how do I configure the autotools project to use a static library?
Bonus points: why is something so easy to do so difficult?