在我的makefile中,我有以下目标,它使用xxd -i将文本/HTML资源“编译”成unsigned char数组。
我将结果封装在一个匿名名称空间和标题保护中,以确保翻译单元内部和之间的多重包含安全。
templates.h:
@echo "#ifndef TEMPLATES_H" > templates.h
@echo "#define TEMPLATES_H" >> templates.h
@echo "// Auto-generated file! Do not modify!" >> templates.h
@echo "// NB: arrays are not null-terminated" >> templates.h
@echo "// (anonymous namespace used to force internal linkage)" >> templates.h
@echo "namespace {" >> templates.h
@echo "namespace templates {" >> templates.h
@cd templates;\
for i in * ;\
do \
echo "Compiling $$i...";\
xxd -i $$i >> ../templates.h;\
done;\
cd ..
@echo "}" >> templates.h
@echo "}" >> templates.h
@echo "#endif" >> templates.h输出,如果我只有一个这样的资源,看起来像这样(实际内容被编辑)
#ifndef TEMPLATES_H
#define TEMPLATES_H
// Auto-generated file! Do not modify!
// NB: arrays are not null-terminated
// (anonymous namespace used to force internal linkage)
namespace {
namespace templates {
unsigned char alert_email_finished_events_html[] = {
0x3c, 0x74, 0x61, 0x62, 0x6c, 0x0d, 0x0a
};
unsigned int alert_email_finished_events_html_len = 7;
}
}
#endif在这些字符数组中应用GCC的__attribute__ ((unused)) 程序,最好的方法是什么呢?--我不希望GCC警告我最终不会在任何给定的TU中使用的资源,但我也不想完全关闭“未使用的变量”警告。
发布于 2011-10-05 11:29:53
我认为一个快速的sed应该可以工作,因为xxd -i的输出是非常正常的:
xxd -i $$i | sed -e 's/ =/ __attribute__((unused)) =/' >> ../templates.hhttps://stackoverflow.com/questions/7660494
复制相似问题