找不到ifdef命令(GNU make 3.81)

Sri*_*ram 3 gnu-make

我有makefile一个简单的helloWorld程序:

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 
Run Code Online (Sandbox Code Playgroud)

当我调用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
Run Code Online (Sandbox Code Playgroud)

我已经在SO上找到了关于这个错误的一些链接但是还没有能够解决这个问题.

Eta*_*ner 7

你的语法错了.你有make指令(ifdef,elseendif)缩进像shell命令一样.

有关如何完成此类操作的信息,请参阅GNU make手册中的条件示例.

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
Run Code Online (Sandbox Code Playgroud)