去除使用log时的警告信息:"LOG_TAG" redefined 的方法

本文介绍在Android源码开发中如何解决LOG_TAG宏重定义的问题。通过简单的代码修改,即可消除编译警告,保持代码整洁。
AI助手已提取文章相关产品:

在Andorid源码开发模式下,当我们使用log时,一般会在头文件或文件开头处定义TAG_LOG宏 ,如下:

#define LOG_TAG "test"

当编译时会出现如下警告:

external/attest/attest.cpp:10:1: warning: "LOG_TAG" redefined
In file included from external/attest/attest.cpp:5:
system/core/include/cutils/log.h:68:1: warning: this is the location of the previous definition

意思是LOG_TAG宏重定义,一般情况下,我们不理这个警告,但是如果你看着这个警告不爽,想除去而后快的话,那么该如何做呢?

其实很简单,如下操作即可:

#ifdef LOG_TAG
#undef LOG_TAG
#define LOG_TAG "test"
#endif

这样就避免宏LOG_TAG重定义了.

您可能感兴趣的与本文相关内容

mobiledog_log.h:34: warning: "LOG_TAG" redefined #define LOG_TAG "MOBILE_DOG" In file included from /home/bba/work/m7000v4/mifi_platform/sdk/ec200a_linux/staging_dir/target-arm_cortex-a7+neon-vfpv4_musl_eabi/usr/include/cutils/log.h:1, from mobiledog_log.h:10, from mobiledog_mgmt.h:5, from mobiledog_plat_mifi.h:8, from mobiledog_plat_mifi.c:1: /home/bba/work/m7000v4/mifi_platform/sdk/ec200a_linux/staging_dir/target-arm_cortex-a7+neon-vfpv4_musl_eabi/usr/include/include/log.h:69: note: this is the location of the previous definition #define LOG_TAG NULL mobiledog_plat_mifi.c: In function 'get_moble_config': mobiledog_plat_mifi.c:133:2: error: unknown type name 'MP_BandSel'; did you mean 'MP_NetSel'? MP_BandSel band_sel; ^~~~~~~~~~ MP_NetSel mobiledog_plat_mifi.c:137:5: warning: implicit declaration of function 'GetBandSelect' [-Wimplicit-function-declaration] GetBandSelect(&band_sel); ^~~~~~~~~~~~~ mobiledog_plat_mifi.c:166:35: error: request for member 'sel_type' in something not a structure or union conf->bandSelectedMode = band_sel.sel_type; ^ mobiledog_plat_mifi.c:167:32: error: 'MP_CellInfo' {aka 'struct <anonymous>'} has no member named 'lte_band' conf->selectedBand = cell_info.lte_band; ^ mobiledog_plat_mifi.c: In function 'set_config_flag': mobiledog_plat_mifi.c:209:2: error: unknown type name 'MP_MobiledogConf'; did you mean 'MP_MobileCode'? MP_MobiledogConf mobile_conf; ^~~~~~~~~~~~~~~~ MP_MobileCode mobiledog_plat_mifi.c:223:3: warning: implicit declaration of function 'GetMobiledogConfig'; did you mean 'GetMobileCode'? [-Wimplicit-function-declaration] GetMobiledogConfig(&mobile_conf); ^~~~~~~~~~~~~~~~~~ GetMobileCode mobiledog_plat_mifi.c:225:20: error: request for member 'flag' in something not a structure or union mobile_conf.flag = (0 == p_value) ? CLR_MOBILEDOG_FLAG(mobile_conf.flag,p_type) : SET_MOBILEDOG_FLAG(mobile_conf.flag,p_type); ^ In file included from mobiledog_plat_mifi.h:8, from mobiledog_plat_mifi.c:1: mobiledog_plat_mifi.c:225:75: error: request for member 'flag' in something not a structure or union mobile_conf.flag = (0 == p_value) ? CLR_MOBILEDOG_FLAG(mobile_conf.flag,p_type) : SET_MOBILEDOG_FLAG(mobile_conf.flag,p_type); ^ mobiledog_mgmt.h:25:42: note: in definition of macro 'CLR_MOBILEDOG_FLAG' #define CLR_MOBILEDOG_FLAG(value,flag) ((value) & (~(0x1<<flag))) ^~~~~ mobiledog_plat_mifi.c:225:121: error: request for member 'flag' in something not a structure or union ag = (0 == p_value) ? CLR_MOBILEDOG_FLAG(mobile_conf.flag,p_type) : SET_MOBILEDOG_FLAG(mobile_conf.flag,p_type); ^ mobiledog_mgmt.h:24:42: note: in definition of macro 'SET_MOBILEDOG_FLAG' #define SET_MOBILEDOG_FLAG(value,flag) ((value) | (0x1<<flag)) ^~~~~ mobiledog_plat_mifi.c:226:3: warning: implicit declaration of function 'SetMobiledogConfig'; did you mean 'get_moble_config'? [-Wimplicit-function-declaration] SetMobiledogConfig(&mobile_conf, &mp_ret); ^~~~~~~~~~~~~~~~~~ get_moble_config mobiledog_plat_mifi.c:234:40: error: request for member 'flag' in something not a structure or union data->config.flag = mobile_conf.flag; ^ mobiledog_plat_mifi.c: In function 'set_config_reboot': mobiledog_plat_mifi.c:256:2: error: unknown type name 'MP_MobiledogConf'; did you mean 'MP_MobileCode'? MP_MobiledogConf mobile_conf;//GetMobiledogConfig ^~~~~~~~~~~~~~~~ MP_MobileCode mobiledog_plat_mifi.c:269:20: error: request for member 'lteDisconnThresholdTableIndex' in something not a structure or union mobile_conf.lteDisconnThresholdTableIndex = p_index; ^ mobiledog_plat_mifi.c:278:83: error: request for member 'lteDisconnThresholdTableIndex' in something not a structure or union data->config.reboot.lte_disconn_reboot_threshold_table_index = mobile_conf.lteDisconnThresholdTableIndex; ^ mobiledog_plat_mifi.c: In function 'check_snapshot': mobiledog_plat_mifi.c:742:2: error: unknown type name 'MP_MobiledogConf'; did you mean 'MP_MobileCode'? MP_MobiledogConf mobile_conf;//GetMobiledogConfig ^~~~~~~~~~~~~~~~ MP_MobileCode mobiledog_plat_mifi.c:765:20: error: request for member 'snapshot' in something not a structure or union memset(mobile_conf.snapshot, 0, sizeof(mobile_conf.snapshot)); ^ mobiledog_plat_mifi.c:765:52: error: request for member 'snapshot' in something not a structure or union memset(mobile_conf.snapshot, 0, sizeof(mobile_conf.snapshot)); ^ mobiledog_plat_mifi.c:766:21: error: request for member 'snapshot' in something not a structure or union strncpy(mobile_conf.snapshot, buff, sizeof(mobile_conf.snapshot)-1); ^ mobiledog_plat_mifi.c:766:56: error: request for member 'snapshot' in something not a structure or union strncpy(mobile_conf.snapshot, buff, sizeof(mobile_conf.snapshot)-1); ^ In file included from /home/bba/work/m7000v4/mifi_platform/sdk/ec200a_linux/staging_dir/target-arm_cortex-a7+neon-vfpv4_musl_eabi/usr/include/cutils/log.h:1, from mobiledog_log.h:10, from mobiledog_mgmt.h:5, from mobiledog_plat_mifi.h:8, from mobiledog_plat_mifi.c:1: mobiledog_plat_mifi.c:776:49: error: request for member 'snapshot' in something not a structure or union MLL_D("snapshot(len=%d)=%s", strlen(mobile_conf.snapshot), mobile_conf.snapshot); ^ mobiledog_plat_mifi.c:776:2: note: in expansion of macro 'MLL_D' MLL_D("snapshot(len=%d)=%s", strlen(mobile_conf.snapshot), mobile_conf.snapshot); ^~~~~ mobiledog_plat_mifi.c:776:72: error: request for member 'snapshot' in something not a structure or union MLL_D("snapshot(len=%d)=%s", strlen(mobile_conf.snapshot), mobile_conf.snapshot); ^ mobiledog_plat_mifi.c:776:2: note: in expansion of macro 'MLL_D' MLL_D("snapshot(len=%d)=%s", strlen(mobile_conf.snapshot), mobile_conf.snapshot); ^~~~~ mobiledog_plat_mifi.c: In function 'check_band_search': mobiledog_plat_mifi.c:959:2: warning: implicit declaration of function 'GetBandSelStat'; did you mean 'GetNetSelStat'? [-Wimplicit-function-declaration] GetBandSelStat(&sel_stat); ^~~~~~~~~~~~~~ GetNetSelStat mobiledog_plat_mifi.c: In function 'check_active_mobile_config': mobiledog_plat_mifi.c:1332:11: error: 'MP_BAND_SEL_MANUAL' undeclared (first use in this function); did you mean 'MP_NET_SEL_MANUAL'? else if (MP_BAND_SEL_MANUAL == conn_conf->bandSelectedMode) ^~~~~~~~~~~~~~~~~~ MP_NET_SEL_MANUAL mobiledog_plat_mifi.c:1332:11: note: each undeclared identifier is reported only once for each function it appears in mobiledog_plat_mifi.c: In function 'check_data_limit': mobiledog_plat_mifi.c:1411:2: warning: implicit declaration of function 'GetFlowSwitch'; did you mean 'GetDataSwitch'? [-Wimplicit-function-declaration] GetFlowSwitch(&mp_switch); ^~~~~~~~~~~~~ GetDataSwitch mobiledog_plat_mifi.c: In function 'check_thermal_level': mobiledog_plat_mifi.c:1466:25: error: 'BATT_THERMAL_LEVEL' undeclared (first use in this function); did you mean 'BATT_POWER_LEVEL'? if (0 != uci_get_value(BATT_THERMAL_LEVEL, &thermal_level)) ^~~~~~~~~~~~~~~~~~ BATT_POWER_LEVEL mobiledog_plat_mifi.c: In function 'check_mobile_proc_health': mobiledog_plat_mifi.c:1514:18: warning: implicit declaration of function 'save' [-Wimplicit-function-declaration] if (0 == save(p_arg)) ^~~~ mobiledog_plat_mifi.c:1516:22: warning: implicit declaration of function 'reboot'; did you mean 'chroot'? [-Wimplicit-function-declaration] if (0 == reboot(p_arg)) ^~~~~~ chroot mobiledog_plat_mifi.c: In function 'check_lte_state_health': mobiledog_plat_mifi.c:1596:9: warning: implicit declaration of function 'cfun' [-Wimplicit-function-declaration] cfun(p_arg); ^~~~ mobiledog_plat_mifi.c: In function 'save': mobiledog_plat_mifi.c:1762:2: error: unknown type name 'MP_MobiledogConf'; did you mean 'MP_MobileCode'? MP_MobiledogConf mobile_conf;//GetMobiledogConfig ^~~~~~~~~~~~~~~~ MP_MobileCode mobiledog_plat_mifi.c:1777:89: error: request for member 'lteDisconnThresholdTableIndex' in something not a structure or union ((data->status.reboot.lte_disconn_reboot_threshold_table_number-1) > mobile_conf.lteDisconnThresholdTableIndex)) ^ mobiledog_plat_mifi.c:1779:23: error: request for member 'lteDisconnThresholdTableIndex' in something not a structure or union ++(mobile_conf.lteDisconnThresholdTableIndex); ^ mobiledog_plat_mifi.c:1781:16: error: request for member 'flag' in something not a structure or union mobile_conf.flag = SET_MOBILEDOG_FLAG(mobile_conf.flag,MOBILEDOG_FLAG_REBOOT); ^ In file included from mobiledog_plat_mifi.h:8, from mobiledog_plat_mifi.c:1: mobiledog_plat_mifi.c:1781:54: error: request for member 'flag' in something not a structure or union mobile_conf.flag = SET_MOBILEDOG_FLAG(mobile_conf.flag,MOBILEDOG_FLAG_REBOOT); ^ mobiledog_mgmt.h:24:42: note: in definition of macro 'SET_MOBILEDOG_FLAG' #define SET_MOBILEDOG_FLAG(value,flag) ((value) | (0x1<<flag)) ^~~~~ mobiledog_plat_mifi.c:1801:23: error: request for member 'archive' in something not a structure or union memset(mobile_conf.archive, 0, sizeof(mobile_conf.archive)); ^ mobiledog_plat_mifi.c:1801:54: error: request for member 'archive' in something not a structure or union memset(mobile_conf.archive, 0, sizeof(mobile_conf.archive)); ^ mobiledog_plat_mifi.c:1802:24: error: request for member 'archive' in something not a structure or union strncpy(mobile_conf.archive, buff, sizeof(mobile_conf.archive)-1); ^ mobiledog_plat_mifi.c:1802:58: error: request for member 'archive' in something not a structure or union strncpy(mobile_conf.archive, buff, sizeof(mobile_conf.archive)-1); ^ mobiledog_plat_mifi.c:1813:46: error: request for member 'archive' in something not a structure or union strncpy(data->config.archive, mobile_conf.archive, sizeof(data->config.archive)-1); ^ mobiledog_plat_mifi.c:1814:36: error: request for member 'flag' in something not a structure or union data->config.flag = mobile_conf.flag; ^ mobiledog_plat_mifi.c:1816:79: error: request for member 'lteDisconnThresholdTableIndex' in something not a structure or union data->config.reboot.lte_disconn_reboot_threshold_table_index = mobile_conf.lteDisconnThresholdTableIndex; ^ In file included from /home/bba/work/m7000v4/mifi_platform/sdk/ec200a_linux/staging_dir/target-arm_cortex-a7+neon-vfpv4_musl_eabi/usr/include/cutils/log.h:1, from mobiledog_log.h:10, from mobiledog_mgmt.h:5, from mobiledog_plat_mifi.h:8, from mobiledog_plat_mifi.c:1: mobiledog_plat_mifi.c:1818:58: error: request for member 'lteDisconnThresholdTableIndex' in something not a structure or union data->config.flag, data->status.flag, mobile_conf.lteDisconnThresholdTableIndex, ^ mobiledog_plat_mifi.c:1817:5: note: in expansion of macro 'MLL_I' MLL_I("new config flag=%08x, new status flag=%08x, index=%d, archive(len=%d)=%s", ^~~~~ mobiledog_plat_mifi.c:1819:27: error: request for member 'archive' in something not a structure or union strlen(mobile_conf.archive), mobile_conf.archive); ^ mobiledog_plat_mifi.c:1817:5: note: in expansion of macro 'MLL_I' MLL_I("new config flag=%08x, new status flag=%08x, index=%d, archive(len=%d)=%s", ^~~~~ mobiledog_plat_mifi.c:1819:49: error: request for member 'archive' in something not a structure or union strlen(mobile_conf.archive), mobile_conf.archive); ^ mobiledog_plat_mifi.c:1817:5: note: in expansion of macro 'MLL_I' MLL_I("new config flag=%08x, new status flag=%08x, index=%d, archive(len=%d)=%s", ^~~~~ mobiledog_plat_mifi.c: In function 'init_platform': mobiledog_plat_mifi.c:1859:2: error: unknown type name 'MP_MobiledogConf'; did you mean 'MP_MobileCode'? MP_MobiledogConf mobile_conf;//GetMobiledogConfig ^~~~~~~~~~~~~~~~ MP_MobileCode mobiledog_plat_mifi.c:1863:41: error: request for member 'state' in something not a structure or union data->config.config.state = mobile_conf.state; ^ mobiledog_plat_mifi.c:1864:44: error: request for member 'interval' in something not a structure or union data->config.config.interval = mobile_conf.interval; ^ mobiledog_plat_mifi.c:1865:41: error: request for member 'logLevelThreshold' in something not a structure or union data->config.config.level = mobile_conf.logLevelThreshold; ^ mobiledog_plat_mifi.c:1866:46: error: request for member 'snapshotInterval' in something not a structure or union data->config.snapshot_interval = mobile_conf.snapshotInterval; ^ mobiledog_plat_mifi.c:1867:67: error: request for member 'mobileInvalidThreshold' in something not a structure or union data->config.reboot.mobile_invalid_reboot_threshold = mobile_conf.mobileInvalidThreshold; ^ mobiledog_plat_mifi.c:1868:64: error: request for member 'lteDisconnThreshold' in something not a structure or union data->config.reboot.lte_disconn_reboot_threshold = mobile_conf.lteDisconnThreshold; ^ mobiledog_plat_mifi.c:1869:76: error: request for member 'lteDisconnThresholdTable' in something not a structure or union memcpy(data->config.reboot.lte_disconn_reboot_threshold_table, mobile_conf.lteDisconnThresholdTable, sizeof(data->config.reboot.lte_disconn_reboot_threshold_table)); ^ mobiledog_plat_mifi.c:1870:76: error: request for member 'lteDisconnThresholdTableIndex' in something not a structure or union data->config.reboot.lte_disconn_reboot_threshold_table_index = mobile_conf.lteDisconnThresholdTableIndex; ^ mobiledog_plat_mifi.c:1871:64: error: request for member 'lteUnknownThreshold' in something not a structure or union data->config.reboot.lte_unknown_reboot_threshold = mobile_conf.lteUnknownThreshold; ^ mobiledog_plat_mifi.c:1872:54: error: request for member 'lteConnHealthThreshold' in something not a structure or union data->config.lte_conn_health_threshold = mobile_conf.lteConnHealthThreshold; ^ mobiledog_plat_mifi.c:1873:59: error: request for member 'lteConnEliminationThreshold' in something not a structure or union data->config.lte_conn_elimination_threshold = mobile_conf.lteConnEliminationThreshold; ^ mobiledog_plat_mifi.c:1874:58: error: request for member 'mobileCfgValidThreshold' in something not a structure or union data->config.mobile_config_valid_threshold = mobile_conf.mobileCfgValidThreshold; ^ mobiledog_plat_mifi.c:1875:48: error: request for member 'cfunThreshold' in something not a structure or union data->config.cfun.cfun_threshold = mobile_conf.cfunThreshold; ^ mobiledog_plat_mifi.c:1876:48: error: request for member 'cfunToken' in something not a structure or union data->config.cfun.cfun_token_max = mobile_conf.cfunToken; ^ mobiledog_plat_mifi.c:1877:58: error: request for member 'nextStopThreshold' in something not a structure or union data->config.next_stop.next_stop_threshold = mobile_conf.nextStopThreshold; ^ mobiledog_plat_mifi.c:1878:60: error: request for member 'nextStopLimitTimes' in something not a structure or union data->config.next_stop.next_stop_limit_times = mobile_conf.nextStopLimitTimes; ^ mobiledog_plat_mifi.c:1879:33: error: request for member 'flag' in something not a structure or union data->config.flag = mobile_conf.flag; ^ mobiledog_plat_mifi.c:1880:42: error: request for member 'archive' in something not a structure or union memcpy(data->config.archive, mobile_conf.archive, sizeof(data->config.archive)); ^ mobiledog_plat_mifi.c: In function 'reload_platform_base_config': mobiledog_plat_mifi.c:2054:2: error: unknown type name 'MP_MobiledogConf'; did you mean 'MP_MobileCode'? MP_MobiledogConf mobile_conf;//GetMobiledogConfig ^~~~~~~~~~~~~~~~ MP_MobileCode In file included from /home/bba/work/m7000v4/mifi_platform/sdk/ec200a_linux/staging_dir/target-arm_cortex-a7+neon-vfpv4_musl_eabi/usr/include/cutils/log.h:1, from mobiledog_log.h:10, from mobiledog_mgmt.h:5, from mobiledog_plat_mifi.h:8, from mobiledog_plat_mifi.c:1: mobiledog_plat_mifi.c:2057:45: error: request for member 'state' in something not a structure or union MLL_I("sta=%d, inr=%d, lvl=%d", mobile_conf.state, mobile_conf.interval, mobile_conf.logLevelThreshold); ^ mobiledog_plat_mifi.c:2057:2: note: in expansion of macro 'MLL_I' MLL_I("sta=%d, inr=%d, lvl=%d", mobile_conf.state, mobile_conf.interval, mobile_conf.logLevelThreshold); ^~~~~ mobiledog_plat_mifi.c:2057:64: error: request for member 'interval' in something not a structure or union MLL_I("sta=%d, inr=%d, lvl=%d", mobile_conf.state, mobile_conf.interval, mobile_conf.logLevelThreshold); ^ mobiledog_plat_mifi.c:2057:2: note: in expansion of macro 'MLL_I' MLL_I("sta=%d, inr=%d, lvl=%d", mobile_conf.state, mobile_conf.interval, mobile_conf.logLevelThreshold); ^~~~~ mobiledog_plat_mifi.c:2057:86: error: request for member 'logLevelThreshold' in something not a structure or union MLL_I("sta=%d, inr=%d, lvl=%d", mobile_conf.state, mobile_conf.interval, mobile_conf.logLevelThreshold); ^ mobiledog_plat_mifi.c:2057:2: note: in expansion of macro 'MLL_I' MLL_I("sta=%d, inr=%d, lvl=%d", mobile_conf.state, mobile_conf.interval, mobile_conf.logLevelThreshold); ^~~~~ mobiledog_plat_mifi.c:2058:41: error: request for member 'state' in something not a structure or union data->config.config.state = mobile_conf.state; ^ mobiledog_plat_mifi.c:2059:44: error: request for member 'interval' in something not a structure or union data->config.config.interval = mobile_conf.interval; ^ mobiledog_plat_mifi.c:2060:41: error: request for member 'logLevelThreshold' in something not a structure or union data->config.config.level = mobile_conf.logLevelThreshold; ^ Makefile:29: recipe for target 'mobiledog_plat_mifi.o' failed make[3]: *** [mobiledog_plat_mifi.o] Error 1 make[3]: Leaving directory '/home/bba/work/m7000v4/mifi_platform/tp-proprietary/mobiledog' Makefile:26: recipe for target '/home/bba/work/m7000v4/mifi_platform/sdk/ec200a_linux/build_dir/target-arm_cortex-a7+neon-vfpv4_musl_eabi/mobiledog-1.0/.built' failed make[2]: *** [/home/bba/work/m7000v4/mifi_platform/sdk/ec200a_linux/build_dir/target-arm_cortex-a7+neon-vfpv4_musl_eabi/mobiledog-1.0/.built] Error 2 make[2]: Leaving directory '/home/bba/work/m7000v4/mifi_platform/sdk/ec200a_linux/package/tp-proprietary/mobiledog'
最新发布
12-03
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值