【发布时间】:2013-11-21 19:30:41
【问题描述】:
我正在尝试为在 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)
我做错了什么?
【问题讨论】:
标签: c linux clang llvm code-coverage