首页 > 解决方案 > 为什么找不到实际存在的头文件?

问题描述

我是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

源码树:

root
 |-----test_ffmpeg.c 
 |-----include 
      

代码:

#include <stdio.h>

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

int main(void)
{

    return 0;
}

编译:

gcc test_ffmpeg.c  -lavcodec -lavdevice -lavfilter -lavformat -lavutil

发生致命错误:

test_ffmpeg.c:3:10: fatal error: ./include/libavcode/avcodec.h: No such file or directory
#include "./include/libavcode/avcodec.h"
      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.

标签: clinuxffmpeg

解决方案


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

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


推荐阅读