C ++项目中ffmpeg的CMake配置 [英] CMake configuration for ffmpeg in C++ project

查看:1577
本文介绍了C ++项目中ffmpeg的CMake配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在Homebrew中安装了ffmpeg(版本4),并且试图在C ++项目中使用各种ffmpeg库,但是在链接过程中出现了多个错误。

I have installed ffmpeg (version 4) with Homebrew and I am trying to use the various ffmpeg libraries in a C++ project, but I am getting multiple errors during linking.

Undefined symbols for architecture x86_64:
  "_av_free", referenced from:
      _main in main.cpp.o
  "_av_packet_alloc", referenced from:
      _main in main.cpp.o
  "_av_parser_init", referenced from:
And so on ... 

我已经包含了以下库

extern "C" {
    #include <libavutil/frame.h>
    #include <libavutil/mem.h>
    #include <libavcodec/avcodec.h>
}

但这仍然行不通。我想我可能已经错过了 CMakeLists.txt 文件中的某些内容,此文件现在看起来像这样:

But still, this doesn't work. I think I might have missed something in my CMakeLists.txt file, which at the moment looks like that :

cmake_minimum_required(VERSION 2.6)
project(decode_encode)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_FLAGS "-D__STDC_CONSTANT_MACROS")

add_executable(decode_encode main.cpp)

我很可能需要指定其他链接标志,但是有没有更好的方法来处理 CMakeLists.txt 文件中的链接部分?

I most likely need to specify additional linking flags, but is there is a better way to handle the linking part in a CMakeLists.txt file?

推荐答案

好,我找到了解决方案。 FFmpeg似乎在CMake中不支持find_package。我必须根据建议在此处手动链接库。

Ok, I've found the solution. It appears that FFmpeg doesn't support find_package in CMake. I had to manually link the libraries as suggested here.

最终的CMakeLists.txt

Final CMakeLists.txt looks like this

cmake_minimum_required(VERSION 2.6)
project(decode_encode)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_FLAGS "-D__STDC_CONSTANT_MACROS")

find_path(AVCODEC_INCLUDE_DIR libavcodec/avcodec.h)
find_library(AVCODEC_LIBRARY avcodec)

find_path(AVFORMAT_INCLUDE_DIR libavformat/avformat.h)
find_library(AVFORMAT_LIBRARY avformat)

find_path(AVUTIL_INCLUDE_DIR libavutil/avutil.h)
find_library(AVUTIL_LIBRARY avutil)

find_path(AVDEVICE_INCLUDE_DIR libavdevice/avdevice.h)
find_library(AVDEVICE_LIBRARY avdevice)

add_executable(decode_encode main.cpp)
target_include_directories(decode_encode PRIVATE ${AVCODEC_INCLUDE_DIR} ${AVFORMAT_INCLUDE_DIR} ${AVUTIL_INCLUDE_DIR} ${AVDEVICE_INCLUDE_DIR})
target_link_libraries(decode_encode PRIVATE ${AVCODEC_LIBRARY} ${AVFORMAT_LIBRARY} ${AVUTIL_LIBRARY} ${AVDEVICE_LIBRARY})

不过,我相信有更好的方法来汇总所有库。

I am sure there is a better way to aggregate all the libraries, though.

这篇关于C ++项目中ffmpeg的CMake配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆