我正在嘗試爲在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)
我該怎麼辦錯了嗎?
沒有任何變化 - 錯誤與上次調用相同 –
作爲最後一招,您可以將完整路徑放在鏈接行上。 「clang --coverage * .c /usr/lib/llvm-3.0/lib/libprofile_rt.a」 –
這也無濟於事。看起來像'--coverage'標誌明確指定了鏈接到庫的不正確路徑 –