当我运行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
答案 0 :(得分:5)
$HOME
在OME
环境中以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 References和Variables from the Environment。