为什么我们找不到实际存在的头文件?

0 c linux ffmpeg

我是C语言初学者,遇到一个问题,找不到头文件,但其实这些头文件都在当前文件中,我看到网上的方法(例如:解决方案)都是加-I选项就可以解决这个问题,不过我很好奇,为什么找不到自己,只能靠-i选项了?

包括路径:

ls .
include  test_ffmpeg.c
ls include/libavcodec/
avcodec.h  avfft.h    dirac.h       dxva2.h  vaapi.h  vdpau.h    videotoolbox.h   xvmc.h
avdct.h    d3d11va.h  dv_profile.h  qsv.h    vda.h    version.h  vorbis_parser.h
Run Code Online (Sandbox Code Playgroud)

源码树:

root
 |-----test_ffmpeg.c 
 |-----include 
      
Run Code Online (Sandbox Code Playgroud)

代码:

#include <stdio.h>

#include "./include/libavcode/avcodec.h"
#include "./include/libvformat/acfomat.h"
#include "./include/libavfilter/avfilter.h"

int main(void)
{

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

编译:

gcc test_ffmpeg.c  -lavcodec -lavdevice -lavfilter -lavformat -lavutil
Run Code Online (Sandbox Code Playgroud)

发生了致命错误:

test_ffmpeg.c:3:10: fatal error: ./include/libavcode/avcodec.h: No such file or directory
#include "./include/libavcode/avcodec.h"
      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
Run Code Online (Sandbox Code Playgroud)

mr.*_*xit 6

您的 include 语句提到了include/libavcode,但存在的路径是include/libavcodec.

添加一个c,您应该会看到不同之处。