问题描述
其他人报告无法,但我发现不仅不能在XCode 4中执行此操作,即使使用命令行中的简单玩具程序也无法执行此操作.我按照此处和此处,这促使我创建了此cov.c文件:
Other people have reported not being able to generate code coverage with XCode 4, but I find not only can I not do it from within XCode 4, I can't do it even with a simple toy program from the command line. I followed the examples given here and here, which led me to create this cov.c file:
#include <stdio.h>
int main (void) {
int i;
for (i = 1; i < 10; i++) {
if (i % 3 == 0)
printf("%d is divisible by 3\n", i);
if (i % 11 == 0)
printf("%d is divisible by 11\n", i);
}
return 0;
}
然后我使用以下命令来尝试产生代码覆盖率:
I then used the following commands in an attempt to generate code coverage:
g++ -c -g -O0 --coverage -o $PWD/obj/cov.o $PWD/cov.c
g++ -g -O0 --coverage -o $PWD/bin/cov $PWD/obj/*.o
$PWD/bin/cov
A,在obj目录中没有cov.gcno文件.实际上,在此之后,我仅有的文件是:冠状病毒obj/cov.obin/cov
Alas, no cov.gcno file exists in the obj directory. In fact, the only files I have after this are:cov.cobj/cov.obin/cov
此外,如果键入nm bin/cov
,则会得到以下信息:
Furthermore, if I type nm bin/cov
, I get the following:
0000000100001048 S _NXArgc
0000000100001050 S _NXArgv
0000000100001060 S ___progname
0000000100000000 A __mh_execute_header
0000000100001058 S _environ
U _exit
0000000100000e40 T _main
U _printf
0000000100001000 s _pvars
U dyld_stub_binder
0000000100000e00 T start
这表明libgcov.a从未链接过.如果我替换
This suggests that libgcov.a was never linked in. If I replace
g++ -g -O0 --coverage -o $PWD/bin/cov $PWD/obj/*.o
具有:
g++ -g -O0 --coverage -o $PWD/bin/cov -lgcov $PWD/obj/*.o
我得到完全相同的结果.
I get the exact same results.
更多信息:
-
g++ --version
产生:"i686-apple-darwin11-llvm-g ++-4.2(GCC)4.2.1(基于Apple Inc.内部版本5658)(LLVM内部版本2336.1.00)" - 我也尝试过使用gcc(是llvm-gcc).
g++ --version
yields: "i686-apple-darwin11-llvm-g++-4.2 (GCC) 4.2.1(Based on Apple Inc. build 5658) (LLVM build 2336.1.00)"- I've also tried using gcc (which is llvm-gcc).
推荐答案
在这个答案.基本上,我将覆盖命令更改为使用clang
而不是g++
(因为示例文件是纯C的,所以我选择了clang
而不是clang++
,这已经证明可以与C ++文件一起使用) .从那里,我可以使用lcov生成类似于我以前从Java/cobertura中看到的输出.
I was able to figure out an answer to this question using help from this answer. Basically, I changed my coverage commands to use clang
instead of g++
(because the example file was pure C, I went with clang
instead of clang++
, which I've verified works just fine with C++ files). From there, I was able to use lcov to generate output similar to what I'm used to seeing from Java/cobertura.
这篇关于Mac OS X Lion和XCode 4/llvm-g ++-4.2不覆盖代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!