我有两个使用常见C ++类的主要函数。
File1:main.cpp
#include <iostream>
#include "HelloAnother.h"
int main() {
HelloAnother::sayHello1();
return 0;
}
File2:main2.cpp
#include <iostream>
#include "HelloAnother.h"
int main() {
HelloAnother::sayHello2();
return 0;
}
File3:HelloAnother.h
#pragma once
class HelloAnother {
public:
static void sayHello1();
static void sayHello2();
};
File4:HelloAnother.cpp
#include <iostream>
#include "HelloAnother.h"
void HelloAnother::sayHello1() {
std::cout << "Hello 1!!!" << std::endl;
}
void HelloAnother::sayHello2() {
std::cout << "Hello 2 !!!" << std::endl;
}
现在我编译了两个可执行文件:
clang-3.8 -o main -fprofile-arcs -ftest-coverage --coverage -g -fPIC -lstdc++ main.cpp HelloAnother.cpp
clang-3.8 -o main2 -fprofile-arcs -ftest-coverage --coverage -g -fPIC -lstdc++ main2.cpp HelloAnother.cpp
现在,我运行./main
你好1 !!!
当我重新运行./main
你好1 !!!
profiling:/media/sf_ubuntu-shared/test-profiling/main.gcda:无法映射:参数无效 分析:/media/sf_ubuntu-shared/test-profiling/HelloAnother.gcda:无法映射:无效参数
一秒钟运行,我在尝试创建/合并.gcda文件时遇到此错误(上面)。
现在,如果我尝试运行./main2
你好2 !!!
profiling:/media/sf_ubuntu-shared/test-profiling/HelloAnother.gcda:无法映射:参数无效
当我生成代码覆盖率报告时,对第二个功能的调用不会显示,就好像没有拨打电话一样。
任何人都可以帮我调试这个问题吗?这个问题似乎与多次运行时合并.gcda文件有关,但不确定如何解决它。
我也尝试过clang-3.5但结果相同。
答案 0 :(得分:0)
经过大量搜索和试用/错误后,这对我有用:
import UIKit
private let reuseIdentifier = "Cell"
class CollectionViewController: UICollectionViewController, UICollectionViewDelegateFlowLayout {
override func viewDidLoad() {
super.viewDidLoad()
collectionView?.backgroundColor = UIColor.brownColor()
self.collectionView!.registerClass(UICollectionViewCell.self, forCellWithReuseIdentifier: reuseIdentifier)
}
// MARK: UICollectionViewDataSource
override func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
return 1
}
override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 10
}
override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath)
cell.backgroundColor = UIColor.blueColor()
return cell
}
}
lcov --gcov-tool=gcov-4.4 --directory . --capture --output-file coverage.main.info
lcov --gcov-tool=gcov-4.4 --directory . --capture --output-file coverage.main2.info