Makefile:运行'make all'时出错

时间:2014-03-19 21:17:47

标签: c++ c gcc compiler-construction

当我运行make all规则中指定的相同gcc命令时,我没有收到任何错误。但是当我运行make all时,我会遇到一堆错误。为什么会这样?

生成文件:

all: program.c
      gcc -I$HOME/ffmpeg/include program.c -L$HOME/ffmpeg/lib -lswscale -lavdevice -lavfilter -lswscale -lswresample -lavformat -lavcodec -lavutil -lz -lm -lpthread -o program

运行gcc命令:

 (No error)

运行make all:

gcc -IOME/ffmpeg/include program.c -LOME/ffmpeg/lib -lswscale -lavdevice -lavfilter -lswscale -lswresample -lavformat -lavcodec -lavutil -lz -lm -lpthread -o program
program.c:15:32: error: libavcodec/avcodec.h: No such file or directory
program.c:16:32: error: libswscale/swscale.h: No such file or directory
program.c:17:34: error: libavformat/avformat.h: No such file or directory
program.c:19: error: expected '=', ',', ';', 'asm' or '__attribute__' before '*' token
program.c:24: error: expected '=', ',', ';', 'asm' or '__attribute__' before '*' token
program.c:95: error: expected ')' before '*' token
program.c:128: error: expected ')' before '*' token
program.c:201: error: expected '=', ',', ';', 'asm' or '__attribute__' before '*' token
program.c: In function 'main':
program.c:253: error: 'AVFrame' undeclared (first use in this function)
program.c:253: error: (Each undeclared identifier is reported only once
program.c:253: error: for each function it appears in.)
program.c:253: error: 'loaded_image' undeclared (first use in this function)
program.c:255: error: 'img_copy' undeclared (first use in this function)
program.c:255: error: 'AV_PIX_FMT_RGB24' undeclared (first use in this function)
program.c:256: error: 'current_frame' undeclared (first use in this function)
make: *** [all] Error 1

2 个答案:

答案 0 :(得分:5)

$HOMEOME环境中以make展开。如果你想让shell扩展它,你需要转义它:

  gcc -I$$HOME/ffmpeg/include ...

现在发生的事情是make正在将$H扩展为空,然后按原样使用其余部分。

答案 1 :(得分:2)

在命令行(shell)上使用$HOME并在Makefile中使用$HOME会有所不同。

在Makefile中,您必须用括号括起变量名,例如

all: program.c
      gcc -I$(HOME)/ffmpeg/include program.c -L$HOME/ffmpeg/lib -lswscale -lavdevice -lavfilter -lswscale -lswresample -lavformat -lavcodec -lavutil -lz -lm -lpthread -o program

有关详情,请参阅Basics of Variable ReferencesVariables from the Environment