I'm trying to generate code coverage files for a small C program compiled with clang on Debian Linux. Here's what I've done:
neuron@debian:~/temp$ ls
main.c test.c test.h
neuron@debian:~/temp$ clang *.c
neuron@debian:~/temp$ ./a.out
0
This is exactly as expected, I can compile and run things. Now trying to enable coverage.
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)
Trying to include the library for linking.
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)
Finding the library:
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)
Here's more verbose output of the last command: http://pastie.org/8468331. What concerns me there:
/usr/bin/../lib/libprofile_rt.a
instead of the path I provided.If we pass the arguments to the linker the output is the same:
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)
What do I do wrong?
Gcov is a source code coverage analysis and statement-by-statement profiling tool. Gcov generates exact counts of the number of times each statement in a program is executed and annotates source code to add instrumentation. Gcov comes as a standard utility with the GNU Compiler Collection (GCC) suite.
The cmake build tool is set up to create Visual Studio project files for running the tests, "clang-test" being the root. Therefore, to run the test from Visual Studio, right-click the clang-test project and select "Build".
To use llvm-cov gcov, you must first build an instrumented version of your application that collects coverage data as it runs. Compile with the -fprofile-arcs and -ftest-coverage options to add the instrumentation. (Alternatively, you can use the --coverage option, which includes both of those other options.)
clang is a C, C++, and Objective-C compiler which encompasses preprocessing, parsing, optimization, code generation, assembly, and linking. Depending on which high-level mode setting is passed, Clang will stop before doing a full link.
Try changing the order of your link line from
clang --coverage -lprofile_rt -L/usr/lib/llvm-3.0/lib *.c
to
clang --coverage -L/usr/lib/llvm-3.0/lib *.c -lprofile_rt
Ok, doesn't seem like the linker is getting your -L for some reason. Maybe try
clang --coverage -Wl,L/usr/lib/llvm-3.0/lib *.c -lprofile_rt
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With