在C源代码中接收makefile参数

时间:2016-12-20 09:53:50

标签: c makefile

我想像这样调用一个makefile:make uj LOCATION = my_room并让my_room出现在打印输出中。

例如:

ifndef LOCATION
    LOCATION = "undefined"
endif

CFLAGS +=  -DLOCATION=$(LOCATION)

应该打印LOCATION是my_room。如果没有给出LOCATION参数,则应该打印undefined。

我尝试过以下内容。 在我的makefile中:

    In file included from ../../uJ/cerberOS_BSP.h:4:0,
                 from ../../uJ/main_upnp.c:3:
../../uJ/main_upnp.c: In function ‘printDiagnostics’:
../../uJ/cerberOS_debug.h:15:59: error: expected expression before ‘)’ token
 #define print(FORMAT,args...) printf_P(PSTR(FORMAT),##args)
                                                           ^
../../uJ/main_upnp.c:35:2: note: in expansion of macro ‘print’
  print(" LOCATION (as s) is %s \n", LOCATION);

然后调用上面的print函数,但这会抛出编译错误。我错过了什么。你能帮忙吗?

编辑: 在编译期间添加了错误。

objNameWritten.Foreground = new SolidColorBrush(Headername[currentIndex]);

1 个答案:

答案 0 :(得分:3)

缺少字符串的引号,因此它将扩展为

print(" LOCATION is %s \n", undefined);

尝试:

CFLAGS += -DLOCATION=\"$(LOCATION)\"

这将扩展为

print(" LOCATION is %s \n", "undefined");

这就是你想要的。