链接时如何解决__gcov_init未定义参考问题 [英] How to resolve __gcov_init undefined reference issue when linking
问题描述
我现在从事C代码覆盖率研究,并遇到以下问题,GCC版本4.4.6:
I now work on C code coverage study and encountered following issue, GCC version 4.4.6:
- 添加了编译器标志
CFLAGS = --coverage
和链接器选项LDFLAGS := --coverage
或LOCAL_LDLIBS := --coverage
,并出现错误:
- Added compiler flag
CFLAGS = --coverage
and linker optionLDFLAGS := --coverage
orLOCAL_LDLIBS := --coverage
and got the error:
undefined reference to '__gcov_init'" and "undefined reference to '__gcov_merge_add'
- 添加了选项
LOCAL_LDFLAGS := --coverage
,并出现了链接错误:
- 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屋!