Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/61.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C Openwrt包的Makefile中错误定义了宏_C_Makefile_C Preprocessor_Openwrt - Fatal编程技术网

C Openwrt包的Makefile中错误定义了宏

C Openwrt包的Makefile中错误定义了宏,c,makefile,c-preprocessor,openwrt,C,Makefile,C Preprocessor,Openwrt,在我正在处理的openwrt包中,我通过向config.In文件添加以下bloc定义了一个新的配置标志: config VENDOR_PREFIX string "Vendor Prefix" default "X_Custom_SE_" 该标志已添加到菜单配置中: 我希望此配置标志的值在我的C代码中作为宏查看。因此,我在包的Makefile中定义了一个宏自定义_前缀,并通过以下方式将定义标志的值分配给它: TARGET_CFLAGS += -DCUSTOM_PREFIX=\

在我正在处理的openwrt包中,我通过向config.In文件添加以下bloc定义了一个新的配置标志:

config VENDOR_PREFIX
    string "Vendor Prefix"
    default "X_Custom_SE_"
该标志已添加到菜单配置中:

我希望此配置标志的值在我的C代码中作为宏查看。因此,我在包的Makefile中定义了一个宏自定义_前缀,并通过以下方式将定义标志的值分配给它:

TARGET_CFLAGS += -DCUSTOM_PREFIX=\"$(CONFIG_VENDOR_PREFIX)\"
然后我尝试在我的C代码中使用我的宏,在结构变量初始化中调用它,如下所示:

struct parameter_struct param1= {CUSTOM_PREFIX"param1", 4};
TARGET_CFLAGS += -DCUSTOM_PREFIX=\\\"$(CONFIG_VENDOR_PREFIX)\\\"
在那之后,我试着编译它。但我有一个编译错误:

/home/user/openwrt//staging_dir/toolchain-mips_mips32_gcc-5.5.0_musl/usr/include -I/home/user/openwrt/staging_dir/toolchain-mips_mips32_gcc-5.5.0_musl/include/fortify -I/home/user/openwrt/staging_dir/toolchain-mips_mips32_gcc-5.5.0_musl/include -I/home/user/openwrt/staging_dir/target-mips_mips32_musl/usr/include -I/home/user/openwrt/staging_dir/target-mips_mips32_musl/usr/include -I/home/user/openwrt/staging_dir/target-mips_mips32_musl/usr/include -DCWMP_VERSION=\"3.0.0\" -I../inc/ -I../dm/ -I../dm/dmtree/ -I../dm/dmtree/common -I../dm/dmtree/tr098 -I../dm/dmtree/tr181 -I../dm/dmtree/upnp -Os -pipe -mips32 -mtune=mips32 -fno-caller-saves -DCONFIG_TARGET_iopsys_brcm63xx_mips -g3 -fno-caller-saves -fno-plt -fhonour-copts -Wno-error=unused-but-set-variable -Wno-error=unused-result -msoft-float -iremap/home/user/openwrt/build_dir/target-mips_mips32_musl/icwmp-curl/icwmp-4.0-2018-03-21:icwmp-4.0-2018-03-21 -Wformat -Werror=format-security -fstack-protector -D_FORTIFY_SOURCE=1 -Wl,-z,now -Wl,-z,relro -DCUSTOM_PREFIX=X_CUSTOM1_SE_ -D_GNU_SOURCE -D_AADJ -MT ../dm/dmtree/common/libdatamodel_la-deviceinfo.lo -MD -MP -MF ../dm/dmtree/common/.deps/libdatamodel_la-deviceinfo.Tpo -c ../dm/dmtree/common/deviceinfo.c  -fPIC -DPIC -o ../dm/dmtree/common/.libs/libdatamodel_la-deviceinfo.o
                 ^
../dm/dmtree/common/deviceinfo.c: At top level:
<command-line>:0:15: error: 'X_CUSTOM1_SE_' undeclared here (not in a function)
../dm/dmtree/common/deviceinfo.c:28:2: note: in expansion of macro 'CUSTOM_PREFIX'
 {CUSTOM_PREFIX"param1", 4}
/home/user/openwrt//staging_dir/toolchain-mips_mips32_gcc-5.5.0_musl/usr/include-I/home/user/openwrt/staging_dir/toolchain-mips_mips32_gcc-5.5.0_musl/include/fortify-I/home/user/openwrt/staging dir/toolchain-mips_-mips32_gcc-5.5.0_musl/include-I/home/user/openwrt/staging-I/home/user/openwrt/staging\u dir/target-mips\u mips32\u musl/usr/include-I/home/user/openwrt/staging\u dir/target-mips\u mips32\u musl/usr/include-DCWMP\u VERSION=“3.0.0”-I../inc/-I../dm/-I../dm/dmtree/-I../dm/dmtree/common-I../dm/tr098-I../dm/dmtree/tr181-I../dm/dmtree/upnp-Os-pipe-mips32-mtune=mips32-fno调用方保存-DCONFIG\u TARGET\u iopsys\u brcm63xx\u mips-g3-fno调用方保存-fno plt-fhonour copts-Wno错误=未使用但设置变量-Wno错误=未使用的结果-msoft float-iremap/home/user/openwrt/build_dir/target-mips_mips32_musl/icwmp curl/icwmp-4.0-2018-03-21:icwmp-4.0-2018-03-21-Wformat-Werror=格式安全-fstack-protector-D_-FORTIFY\u-SOURCE=1-Wl,--z,now-Wl,--z,relro-DCUSTOM\u PREFIX=X\u CUSTOM1\u SE\u-D\u GNU\u SOURCE-D\u AADJ-MT../dm/dmtree/common/libdatamodel\u la-deviceinfo.lo-MD-MP-MF../dm/dmtree/common/.deps/libdatamodel\u la-deviceinfo.Tpo-c../dm/dmtree/common/deviceinfo.c-fPIC-DPIC-o../dm/dmtree/common/.libs/libdatamodel\u la-deviceinfo.o
^
../dm/dmtree/common/deviceinfo.c:在顶层:
:0:15:错误:“X_CUSTOM1_SE_”未在此处声明(不在函数中)
../dm/dmtree/common/deviceinfo.c:28:2:注意:在宏“CUSTOM_PREFIX”的扩展中
{自定义前缀“param1”,4}
结构参数_struct param1={CUSTOM_前缀“param1”,4}; 似乎c程序不接受它作为字符串。
我的宏定义有什么错误吗?

正如我预料的那样,我在我的文章标题中指出,错误在于Makefile中宏的定义。在Openwrt Makefile中,宏的定义应如下所示:

struct parameter_struct param1= {CUSTOM_PREFIX"param1", 4};
TARGET_CFLAGS += -DCUSTOM_PREFIX=\\\"$(CONFIG_VENDOR_PREFIX)\\\"

尝试不使用
\”
?可能
配置供应商前缀
已经是一个字符串。@EugeneSh。不,它不起作用。同样的问题,您可能可以通过
\define STR(x)\x
然后
STR(自定义前缀)来解决它
。但它不能解释为什么这不起作用。@EugeneSh。如果我使用你的建议,很好,我不会得到编译错误。但是我在执行中没有得到很好的结果。因为在c代码中,结构初始化将是结构参数\u struct param1={STR(自定义前缀)“param1”,4};所以我得到的是字符串“CUSTOM\u PREFIXparam1”“但我想要它X_CUSTOM1_SE_param1