Makefile shell调用中的哈希会导致意外行为 下面的命令打印一个特定C++头的绝对路径,根据G++认为它是在哪里。 echo \#include\<ham/hamsterdb.h\> | g++ -M -x c++-header - | grep hamsterdb.hpp | sed -e 's/-: //' -e 's/ \\//'
这将输出一个新行。我认为是hash(“#”)字符在搅乱make;如果我像这样重写Makefile shell调用中的哈希会导致意外行为 下面的命令打印一个特定C++头的绝对路径,根据G++认为它是在哪里。 echo \#include\<ham/hamsterdb.h\> | g++ -M -x c++-header - | grep hamsterdb.hpp | sed -e 's/-: //' -e 's/ \\//',shell,g++,makefile,echo,Shell,G++,Makefile,Echo,这将输出一个新行。我认为是hash(“#”)字符在搅乱make;如果我像这样重写文件=…行: FILE=$(shell echo \#include\<ham/hamsterdb.h\>) FILE=$(shell echo\#include\) 输出仍然是空的。您只需要再引用一点: FILE=$(shell echo \\\#include\<ham/hamsterdb.h\> ... ^^^ FILE=$(shell echo
文件=…
行:
FILE=$(shell echo \#include\<ham/hamsterdb.h\>)
FILE=$(shell echo\#include\)
输出仍然是空的。您只需要再引用一点:
FILE=$(shell echo \\\#include\<ham/hamsterdb.h\> ...
^^^
FILE=$(shell echo\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\包含\。。。
^^^
为
make
本身引用一次,为shell引用第二次(shell需要“查看”\\\\
)。为了在函数中使用哈希,必须两次转义:一次用于make,一次用于shell
就是
FILE = $(shell echo \\\#include\ \<ham/hamsterdb.h\>)
FILE = $(shell echo \\\#include\ \<ham/hamsterdb.h\>)
FILE = $(shell echo '\#include <ham/hamsterdb.h>')