2013-11-09 119 views
6

我正在嘗試爲在Debian Linux上使用clang編譯的小型C程序生成代碼覆蓋文件。以下是我所做的:叮噹中的代碼覆蓋範圍

[email protected]:~/temp$ ls 
main.c test.c test.h 
[email protected]:~/temp$ clang *.c 
[email protected]:~/temp$ ./a.out 
0 

這完全如我所料,我可以編譯和運行的東西。現在試圖啓用覆蓋。

[email protected]:~/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) 

試圖包含鏈接庫。

[email protected]:~/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) 

查找庫:

[email protected]:~/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 
[email protected]:~/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而不是我提供的路徑。

如果我們傳遞參數給連接器的輸出是一樣的:

[email protected]:~/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) 

我該怎麼辦錯了嗎?

回答

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 
+0

沒有任何變化 - 錯誤與上次調用相同 –

+0

作爲最後一招,您可以將完整路徑放在鏈接行上。 「clang --coverage * .c /usr/lib/llvm-3.0/lib/libprofile_rt.a」 –

+0

這也無濟於事。看起來像'--coverage'標誌明確指定了鏈接到庫的不正確路徑 –

2

我已經能夠解決這個問題的唯一方法是通過創建一個符號鏈接到LLVM /鐺正在尋找庫。我認爲這是程序包維護人員管理主機系統使用哪個功能庫的一種方式。

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