gpt4 book ai didi

c - Openwrt包的Makefile中错误定义宏

转载 作者:太空宇宙 更新时间:2023-11-03 23:38:56 52 4
gpt4 key购买 nike

在我正在处理的 openwrt 包中,我通过将以下 bloc 添加到 Config.in 文件来定义一个新的配置标志:

config VENDOR_PREFIX
string "Vendor Prefix"
default "X_Custom_SE_"

在 menuconfig 中很好地添加了标志:

enter image description here

我希望这个配置标志的值在我的 C 代码中被视为一个宏。因此,我在包的 Makefile 中定义了一个宏 CUSTOM_PREFIX,并通过这种方式为其分配了已定义标志的值:

TARGET_CFLAGS += -DCUSTOM_PREFIX=\"$(CONFIG_VENDOR_PREFIX)\"

然后我尝试在我的 C 代码中使用我的宏,方法是在这样的结构变量初始化中调用它:

struct parameter_struct param1= {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_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}

struct parameter_struct param1= {CUSTOM_PREFIX"param1", 4};似乎 c 程序不接受它作为字符串。我的宏定义有问题吗?

最佳答案

正如我所预料的那样,我在帖子标题中指出错误出在 Makefile 中宏的定义中。在 Openwrt Makefile 中,宏的定义应该是这样的:

TARGET_CFLAGS += -DCUSTOM_PREFIX=\\\"$(CONFIG_VENDOR_PREFIX)\\\"

关于c - Openwrt包的Makefile中错误定义宏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50953309/

52 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com