小编Aks*_*pal的帖子

将$(shell)中的make变量定义为C中的字符串

我正在使用STM32f4系列芯片上的嵌入式应用程序的makefile编译代码.

当我做:

Makefile文件:

DEFINES += -DGIT_HASH="test hash"
Run Code Online (Sandbox Code Playgroud)

在我的main.c:

const char * git_hash = GIT_HASH;
Run Code Online (Sandbox Code Playgroud)

当我打印出来时git_hash,我明白了test hash.

我想做的是:

Makefile文件:

COMMIT_HASH = $(shell git rev-parse HEAD)
DEFINES += -DGIT_HASH=$(COMMIT_HASH)
Run Code Online (Sandbox Code Playgroud)

在我的main.c:

const char * git_hash = GIT_HASH;
Run Code Online (Sandbox Code Playgroud)

我收到一个错误:

<command-line>:0:10: error: 'c1920a032c487a55b1b109d8774faf05e2ba42d0' undeclared here (not in a function)
src/run/main.c:173:25: note: in expansion of macro 'GIT_HASH'
 const char * git_hash = GIT_HASH;
Run Code Online (Sandbox Code Playgroud)

我想知道为什么COMMIT_HASH不像字符串一样对待它.任何见解将不胜感激.

c makefile

1
推荐指数
1
解决办法
1823
查看次数

标签 统计

c ×1

makefile ×1