致命错误:libavcodec / avcodec.h没有这样的文件或目录

时间:2018-04-19 14:03:18

标签: c ubuntu makefile ffmpeg

我尝试在我的ubuntu1604平台上调试ffmpeg,但它总是说它找不到头文件,但实际上我在编译代码中包含了头文件。

这是错误消息: error message

这是我的测试代码:

 #include <stdio.h>
 #include "libavcodec/avcodec.h"
 #include "libavformat/avformat.h"
 #include "libswscale/swscale.h"

int main(int argc, char * argv[]){
av_register_all();
AVFormatContext *pFormatCtx = NULL;

// Open video file
if (avformat_open_input(&pFormatCtx, argv[1], NULL, NULL) !=0 )
    return -1; // Couldn't open file

// Retrieve stream information
if (avformat_find_stream_info(pFormatCtx, NULL) < 0)
    return -1; // Couldn't find stream information

// Dump information about file onto standard error
av_dump_format(pFormatCtx, 0, argv[1], 0);

int i;
AVCodecContext *pCodecCtxOrig = NULL;
AVCodecContext *pCodecCtx = NULL;

// Find the first video stream
int videoStream = -1;
for(i=0; i<pFormatCtx->nb_streams; i++)
    if (pFormatCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO){
        videoStream = 1;
        break;
    }

if (videoStream == -1)
    return -1; // Didn't find a video stream

// Get a pointer to the codec context for the video stream
pCodecCtx = pFormatCtx->streams[videoStream]->codec;

AVCodec *pCodec = NULL;
// Find the decoder for the video stream
pCodec = avcodec_find_decoder(pCodecCtx->codec_id);
if (pCodec==NULL){
    fprintf(stderr, "Unsupported codec!\n");
    return -1; // Codec not found
}   

// Copy context
pCodecCtx = avcodec_alloc_context3(pCodec);
if (avcodec_copy_context(pCodecCtx, pCodecCtxOrig) !=0 ){
    fprintf(stderr, "Couldn't copy codec context");
    return -1; // Error copying codec context
}

// Open codec
if (avcodec_open2(pCodecCtx, pCodec, NULL)<0)
    return -1; // Could not open codec

AVFrame *pFrame = NULL;
// Allocate video fream
pFrame = av_frame_alloc();

// Allocate an AVFrame structure
AVFrame *pFrameRGB = NULL;
pFrameRGB = av_frame_alloc();
if(pFrameRGB == NULL)
    return -1;
}

以下是我的Makefile

C++     = gcc
INCLUDE_DIR = ./include
LIB_DIR     = ./lib
BIN_DIR     = ./build/bin
TARGET      = $(BIN_DIR)/mk-screen-caps

INC_PATH    += -I./ -I$(INCLUDE_DIR)
LIBS        += -lstdc++ -lm -lgcc_s -lgcc -lc
LIBS        += $(LIB_DIR)/libavcodec.a $(LIB_DIR)/libavdevice.a 
$(LIB_DIR)/libavfilter.a 
LIBS        += $(LIB_DIR)/libavformat.a $(LIB_DIR)/libavutil.a 
$(LIB_DIR)/libfdk-aac.a 
LIBS        += $(LIB_DIR)/libmp3lame.a $(LIB_DIR)/libopus.a 
$(LIB_DIR)/libpostproc.a 
LIBS        += $(LIB_DIR)/libswresample.a $(LIB_DIR)/libswscale.a 
$(LIB_DIR)/libx264.a 
LIBS        += $(LIB_DIR)/libx265.a $(LIB_DIR)/libyasm.a

C++_FLAGS   += -pipe -g -Wall -o0 

C_FILES     += $(wildcard ./*.c);
CPP_FILES   += $(wildcard ./*.cpp)
HEAD_FILES  += $(wildcard $(INCLUDE_DIR)/*.h)

C_OBJS=$(C_FILES:.c=.o)
CPP_OBJS=$(CPP_FILES:.cpp=.O)

all: $(TARGET)
$(TARGET): $(CPP_OBJS)
$(C++)  $(C++_FLAGS) -o $@ $(CPP_FILES) $(LIBS)

%.o: %.c $(HEAD_FILES)
    $(C++) -c $(C_FILES) $(INC_PATH) $< -o $@
%.O: %.cpp $(HEAD_FILES)
    $(C++) -c $(CPP_FLAGS) $(INC_PATH) $< -o $@

clean:
    rm -f $(TARGET) $(C_OBJS) $(CPP_OBJS)

以下是我的目录信息:

mk-screen-caps(父母代理人)

- 构建

- 仓

- 包括

- (需要包含文件和目录)

- LIB

- (需要的文件夹)

1 个答案:

答案 0 :(得分:0)

根据发布的错误消息,您的INC_PATH Make变量未被使用。因此,gcc找不到avcodec.h

也许您已经更改了Makefile,因为如果我运行上面发布的那个,它实际上会使用模式规则%.O: %.cpp $(HEAD_FILES)

尝试运行make --debug。对我来说,这导致:

$ make --debug
GNU Make 4.1
Built for aarch64-unknown-linux-gnu
Copyright (C) 1988-2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Reading makefiles...
Updating goal targets....
 File 'all' does not exist.
   File 'build/bin/mk-screen-caps' does not exist.
     File 'test.O' does not exist.
    Must remake target 'test.O'.
gcc -c  -I./ -I./include test.cpp -o test.O
test.cpp:2:33: fatal error: libavcodec/avcodec.h: No such file or directory
compilation terminated.
Makefile:31: recipe for target 'test.O' failed
make: *** [test.O] Error 1

它也失败了,因为我在libavcodec/avcodec.h.的任何目录中都没有include。但可以看出,include目录列表实际上是在gcc的调用中使用的。