找不到 ifdef 命令(GNU make 3.81)
ifdef command not found (GNU make 3.81)
对于一个简单的 helloWorld 程序,我有以下 makefile
:
helloWorld: helloWorld.cpp
echo "Argument entered is $(foo)"
ifdef foo
echo "Defined.";
else
echo "Not defined.";
endif
g++ -Wall -pedantic -g helloWorld.cpp -o h
当我像这样从命令行调用 make
时:make foo=bar
,我收到以下错误:
bar
"not set"
echo "Argument entered is bar"
Argument entered is bar
ifdef foo
make: ifdef: Command not found
make: *** [helloWorld] Error 127
关于这个错误,我已经浏览了 SO 上的一些链接,但还没有解决这个问题。
你的语法有误。您的 make 指令(ifdef
、else
和 endif
)像 shell 命令一样缩进。
请参阅 GNU make 手册中的 Example of a Conditional 以了解如何执行此类操作。
libs_for_gcc = -lgnu
normal_libs =
foo: $(objects)
ifeq ($(CC),gcc)
$(CC) -o foo $(objects) $(libs_for_gcc)
else
$(CC) -o foo $(objects) $(normal_libs)
endif
对于一个简单的 helloWorld 程序,我有以下 makefile
:
helloWorld: helloWorld.cpp
echo "Argument entered is $(foo)"
ifdef foo
echo "Defined.";
else
echo "Not defined.";
endif
g++ -Wall -pedantic -g helloWorld.cpp -o h
当我像这样从命令行调用 make
时:make foo=bar
,我收到以下错误:
bar
"not set"
echo "Argument entered is bar"
Argument entered is bar
ifdef foo
make: ifdef: Command not found
make: *** [helloWorld] Error 127
关于这个错误,我已经浏览了 SO 上的一些链接,但还没有解决这个问题。
你的语法有误。您的 make 指令(ifdef
、else
和 endif
)像 shell 命令一样缩进。
请参阅 GNU make 手册中的 Example of a Conditional 以了解如何执行此类操作。
libs_for_gcc = -lgnu
normal_libs =
foo: $(objects)
ifeq ($(CC),gcc)
$(CC) -o foo $(objects) $(libs_for_gcc)
else
$(CC) -o foo $(objects) $(normal_libs)
endif