如何快速验证宏定义是否生效
1.前言
我们在使用宏控制代码模块式,不知道宏控制有没有生效,整体编译验证又很费时间,故在此提出一种便捷方法。
2.正文
可以使用#error插入代码块进行编译测试,对特定目录进行编译--------make 目录名_build
Z:\tmp\RTL3-4-14b\users\rc\Makefile
ifneq ($(CONFIG_APP_CHANGE_FACTORY_SETTINGS),y)
CFLAGS += -DCONFIG_CHANGE_FACTORY_SETTINGS
endif
Z:\tmp\RTL3-4-14b\users\rc\reload.c
#ifdef CONFIG_CHANGE_FACTORY_SETTINGS
#error 11111111111
else if (i==3)
{
printf("Going to Reload ChangeFactorySettingsDefault\n");
system("flash changefactorysettings");
system("reboot");
}
#else
#error 22222222222222222222
#endif//CONFIG_CHANGE_FACTORY_SETTINGS
/work/shuzhi/tmp/RTL3-4-14b/users
[ ! -d "rc" ] || make -C rc || exit $?
make[2]: Entering directory `/work/shuzhi/tmp/RTL3-4-14b/users/rc'
msdk-linux-gcc -Os -DCONFIG_RTL_819X -DCONFIG_RTL_8197F -DCOMNECT_PRODUCT_NuCom -DCOMNECT_PRODUCT=\"NuCom\" -c -o reload.o reload.c
reload.c: In function 'main':
reload.c:1403:2: error: #error 22222222222222222222
#error 22222222222222222222
^
reload.c:1478:10: warning: passing argument 1 of 'chk_wlanSch_ksRule' from incompatible pointer type [enabled by default]
chk_wlanSch_ksRule(&ks[i],i);
^
reload.c:745:6: note: expected 'struct ps_info *' but argument is of type 'struct ps_info (*)[10]'
void chk_wlanSch_ksRule(struct ps_info *ks, int index)
^
reload.c:1489:10: warning: passing argument 1 of 'chk_wlanSch_ksRule' from incompatible pointer type [enabled by default]
chk_wlanSch_ksRule(&ks[i],i);
^
reload.c:745:6: note: expected 'struct ps_info *' but argument is of type 'struct ps_info (*)[10]'
void chk_wlanSch_ksRule(struct ps_info *ks, int index)
^
reload.c:1515:10: warning: passing argument 1 of 'chk_wlanSch_ksRule' from incompatible pointer type [enabled by default]
chk_wlanSch_ksRule(&ks[i],i);
^
reload.c:745:6: note: expected 'struct ps_info *' but argument is of type 'struct ps_info (*)[10]'
void chk_wlanSch_ksRule(struct ps_info *ks, int index)
^
reload.c:1526:10: warning: passing argument 1 of 'chk_wlanSch_ksRule' from incompatible pointer type [enabled by default]
chk_wlanSch_ksRule(&ks[i],i);
^
reload.c:745:6: note: expected 'struct ps_info *' but argument is of type 'struct ps_info (*)[10]'
void chk_wlanSch_ksRule(struct ps_info *ks, int index)
^
reload.c:1558:10: warning: passing argument 1 of 'chk_wlanSch_ksRule' from incompatible pointer type [enabled by default]
chk_wlanSch_ksRule(&ks[i],i);
^
reload.c:745:6: note: expected 'struct ps_info *' but argument is of type 'struct ps_info (*)[10]'
void chk_wlanSch_ksRule(struct ps_info *ks, int index)
^
reload.c:1569:10: warning: passing argument 1 of 'chk_wlanSch_ksRule' from incompatible pointer type [enabled by default]
chk_wlanSch_ksRule(&ks[i],i);
^
reload.c:745:6: note: expected 'struct ps_info *' but argument is of type 'struct ps_info (*)[10]'
void chk_wlanSch_ksRule(struct ps_info *ks, int index)
^
make[2]: *** [reload.o] Error 1
make[2]: Leaving directory `/work/shuzhi/tmp/RTL3-4-14b/users/rc'
make[1]: *** [rc] Error 2
make[1]: Leaving directory `/work/shuzhi/tmp/RTL3-4-14b/users'
make: *** [rc_build] Error 2
shuzhi@software-server:~/tmp/RTL3-4-14b$