链接时如何解决__gcov_init未定义参考问题 [英] How to resolve __gcov_init undefined reference issue when linking

查看:2176
本文介绍了链接时如何解决__gcov_init未定义参考问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在从事C代码覆盖率研究,并遇到以下问题,GCC版本4.4.6:

I now work on C code coverage study and encountered following issue, GCC version 4.4.6:

  1. 添加了编译器标志CFLAGS = --coverage和链接器选项LDFLAGS := --coverageLOCAL_LDLIBS := --coverage,并出现错误:
  1. Added compiler flag CFLAGS = --coverage and linker option LDFLAGS := --coverage or LOCAL_LDLIBS := --coverage and got the error:

undefined reference to '__gcov_init'" and "undefined reference to '__gcov_merge_add'

  1. 添加了选项LOCAL_LDFLAGS := --coverage,并出现了链接错误:
  1. Added option LOCAL_LDFLAGS := --coverage, and got link error:

libgcov.a(_gcov.o): in function __gcov_set_sampling_rate: undefined reference to '__gcov_sampling_rate' libgcov.a(_gcov.o): in function gcov_exit: undefined reference to '__gcov_pmu_profile_filename' libgcov.a(_gcov.o): in function __gcov_init: undefined reference to '__gcov_pmu_profile_options' '__gcov_pmu_top_n_address'

libgcov.a(_gcov.o): in function __gcov_set_sampling_rate: undefined reference to '__gcov_sampling_rate' libgcov.a(_gcov.o): in function gcov_exit: undefined reference to '__gcov_pmu_profile_filename' libgcov.a(_gcov.o): in function __gcov_init: undefined reference to '__gcov_pmu_profile_options' '__gcov_pmu_top_n_address'

有人可以提供有关此问题的建议吗?

Can anyone help to provide some suggestions on this issue?

推荐答案

尝试以下方法:

使用以下选项编译要为其生成coverage的代码:

Compile the code for which you want to generate the coverage with these options:

CFLAGS: -fprofile-arcs -ftest-coverage

LFLAGS: -lgcov --coverage

如果这不能解决问题,请提供有关应用程序结构的信息,即是单个程序还是包含共享/静态库的应用程序等.

If this doesn't solve the problem, then please provide some information on the structure of your application, i.e. whether its single program or an application involving shared/static libraries etc.

希望有帮助!

这篇关于链接时如何解决__gcov_init未定义参考问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆