6

我正在尝试为在 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)

我做错了什么?

4

2 回答 2

2

尝试将链接行的顺序从

clang --coverage -lprofile_rt -L/usr/lib/llvm-3.0/lib *.c

clang --coverage  -L/usr/lib/llvm-3.0/lib *.c -lprofile_rt

好的,似乎链接器出于某种原因没有得到您的 -L 。也许试试

clang --coverage  -Wl,L/usr/lib/llvm-3.0/lib *.c -lprofile_rt
于 2013-11-09T19:24:59.793 回答
2

我能够解决此问题的唯一方法是创建一个指向 LLVM/clang 正在寻找库的位置的符号链接。我认为这是包维护者管理主机系统使用哪个功能库的一种方式。

ln -s /usr/lib/llvm-3.0/lib/libprofile_rt.a /usr/lib/libprofile_rt.a

覆盖范围和其他可选-f<***>配置文件功能按预期工作。我可以通过添加详细-v开关来验证这一点。

Debian clang version 3.0-6.2 (tags/RELEASE_30/final) (based on LLVM 3.0)
Target: arm-unknown-linux-gnueabihf
Thread model: posix
 "/usr/bin/clang" -cc1 -triple armv4t-unknown-linux-gnueabihf -S -disable-free -disable-llvm-verifier -main-file-name example.c -mrelocation-model static -mdisable-fp-elim -mconstructor-aliases -target-abi apcs-gnu -target-cpu arm1136jf-s -mfloat-abi hard -target-linker-version 2.22 -momit-leaf-frame-pointer -v -femit-coverage-notes -femit-coverage-data -resource-dir /usr/bin/../lib/clang/3.0 -fmodule-cache-path /var/tmp/clang-module-cache -internal-isystem /usr/local/include -internal-isystem /usr/bin/../lib/clang/3.0/include -internal-externc-isystem /usr/include/arm-linux-gnueabihf -internal-externc-isystem /usr/include -ferror-limit 19 -fmessage-length 130 -fno-signed-char -fgnu-runtime -fobjc-runtime-has-arc -fobjc-runtime-has-weak -fobjc-fragile-abi -fdiagnostics-show-option -fcolor-diagnostics -o /tmp/example-lLKOP1.s -x c example.c
clang -cc1 version 3.0 based upon llvm 3.0 hosted on arm-unknown-linux-gnueabihf
ignoring nonexistent directory "/usr/bin/../lib/clang/3.0/include"
ignoring nonexistent directory "/usr/bin/../lib/clang/3.0/include"
ignoring duplicate directory "/usr/local/include"
ignoring duplicate directory "/usr/include/arm-linux-gnueabihf"
ignoring duplicate directory "/usr/include/arm-linux-gnueabihf"
ignoring duplicate directory "/usr/include/arm-linux-gnueabihf"
ignoring duplicate directory "/usr/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include
 /usr/include/arm-linux-gnueabihf
 /usr/include
 /usr/include/clang/3.0/include/
 /usr/lib/gcc/arm-linux-gnueabihf/4.6/include/
 /usr/lib/gcc/arm-linux-gnueabihf/4.6/include-fixed/
End of search list.
 "/usr/bin/as" -o /tmp/example-WbJHFT.o /tmp/example-lLKOP1.s
 "/usr/bin/ld" -X --hash-style=both --build-id --eh-frame-hdr -m armelf_linux_eabi -dynamic-linker /lib/ld-linux-armhf.so.3 -o example.o /usr/lib/gcc/arm-linux-gnueabihf/4.6/../../../arm-linux-gnueabihf/crt1.o /usr/lib/gcc/arm-linux-gnueabihf/4.6/../../../arm-linux-gnueabihf/crti.o /usr/lib/gcc/arm-linux-gnueabihf/4.6/crtbegin.o -L/usr/lib/gcc/arm-linux-gnueabihf/4.6/../../../arm-linux-gnueabihf -L/lib/arm-linux-gnueabihf -L/usr/lib/arm-linux-gnueabihf -L/usr/lib/gcc/arm-linux-gnueabihf/4.6 -L/usr/lib/gcc/arm-linux-gnueabihf/4.6/../../../arm-linux-gnueabihf -L/usr/lib/gcc/arm-linux-gnueabihf/4.6/../../.. -L/lib/arm-linux-gnueabihf -L/lib -L/usr/lib/arm-linux-gnueabihf -L/usr/lib /tmp/example-WbJHFT.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed \
 /usr/lib/gcc/arm-linux-gnueabihf/4.6/crtend.o \
 /usr/lib/gcc/arm-linux-gnueabihf/4.6/../../../arm-linux-gnueabihf/crtn.o \
 /usr/bin/../lib/libprofile_rt.a
于 2013-11-30T14:06:53.440 回答