我正在尝试为在 Debian Linux 上使用 clang 编译的小型 C 程序生成代码覆盖率文件。这是我所做的:
neuron@debian:~/temp$ ls
main.c test.c test.h
neuron@debian:~/temp$ clang *.c
neuron@debian:~/temp$ ./a.out
0
这完全符合预期,我可以编译和运行东西。现在尝试启用覆盖。
neuron@debian:~/temp$ clang --coverage *.c
/usr/bin/ld: cannot find /usr/bin/../lib/libprofile_rt.a: No such file or directory
clang: error: linker command failed with exit code 1 (use -v to see invocation)
试图包含用于链接的库。
neuron@debian:~/temp$ clang --coverage -lprofile_rt *.c
/usr/bin/ld: cannot find -lprofile_rt
clang: error: linker command failed with exit code 1 (use -v to see invocation)
寻找图书馆:
neuron@debian:~/temp$ find / -name \*profile_rt\* 2>/dev/null
/usr/lib/llvm-3.0/lib/libprofile_rt.so
/usr/lib/llvm-3.0/lib/libprofile_rt.a
neuron@debian:~/temp$ clang --coverage -lprofile_rt -L/usr/lib/llvm-3.0/lib *.c
/usr/bin/ld: cannot find /usr/bin/../lib/libprofile_rt.a: No such file or directory
clang: error: linker command failed with exit code 1 (use -v to see invocation)
这是最后一个命令的更详细的输出:http: //pastie.org/8468331。我担心的是:
- 链接器使用大量 gcc 库来链接(尽管这可能是 llvm 没有自己的 binunitls 的结果);
- 正在搜索分析库,
/usr/bin/../lib/libprofile_rt.a
而不是我提供的路径。
如果我们将参数传递给链接器,则输出是相同的:
neuron@debian:~/temp$ clang --coverage -Wl,-L/usr/lib/llvm-3.0/lib *.c -lprofile_rt
/usr/bin/ld: cannot find /usr/bin/../lib/libprofile_rt.a: No such file or directory
clang: error: linker command failed with exit code 1 (use -v to see invocation)
我做错了什么?