在Cmake中链接libavcodec,find_library不适用于任何库 [英] Linking libavcodec in Cmake, find_library won't work with any library

查看:349
本文介绍了在Cmake中链接libavcodec,find_library不适用于任何库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编译使用libavcodec的cpp代码:

  #include< libavcodec / avcodec.h> 

我尝试了



<$ p $的所有变体p> find_package()

其名称类似于 ffmpeg 我得到的

 在CMakeLists.txt上的CMake警告:17(find_package):
通过不在CMAKE_MODULE_PATH中提供 Findffmpeg.cmake,该项目使
要求CMake查找 ffmpeg提供的软件包配置文件,但
CMake找不到一个。

找不到 ffmpeg提供的具有以下名称的
的软件包配置文件:

ffmpegConfig.cmake
ffmpeg-config。 cmake

将 ffmpeg的安装前缀添加到CMAKE_PREFIX_PATH或将
ffmpeg_DIR设置到包含上述文件之一的目录中。如果 ffmpeg
提供了单独的开发包或SDK,请确保已安装

顺便说一句,我做了 sudo apt install -y ffmpeg

我正在使用

  add_executable(my_executable $ {sources})

最小的工作示例



CMakeLists.txt

  cmake_minimum_required(版本3.1.0)

项目(hello)

find_library(AVCODEC_LIBRARY avcodec)

add_executable(hello main.cpp)

target_link_libraries(hello PRIVATE $ {AVCODEC_LIBRARY})

main.cpp

  #include< iostream> 
使用命名空间std;

int main()
{
cout<< 你好,世界!;
返回0;
}

输出:

  lz @ vm:〜/ mcve $ cmake。 
-C编译器标识为GNU 7.2.0
-CXX编译器标识为GNU 7.2.0
-检查工作的C编译器:/ usr / bin / cc
-检查工作的C编译器:/ usr / bin / cc-工作
-检测C编译器ABI信息
-检测C编译器ABI信息-完成
-检测C编译功能
-检测C编译功能-完成
-检查工作的CXX编译器:/ usr / bin / c ++
-检查工作的CXX编译器:/ usr / bin / c ++-作品
-检测CXX编译器ABI信息
-检测CXX编译器ABI信息-完成
-检测CXX编译功能
-检测CXX编译功能-完成
CMake错误:此项目中使用了以下变量,但是将它们设置为NOTFOUND。
请设置它们或确保在CMake文件中对其进行了正确设置和测试:
AVCODEC_LIBRARY
由目标你好链接到目录/ home / lz / mcve

-配置不完整,发生错误!
另请参见 /home/lz/mcve/CMakeFiles/CMakeOutput.log。


解决方案

这是缺少的内容(即使 libavcodec 出现在我系统的某些文件夹中)

  sudo apt install -y libavcodec- dev libavformat-dev libavdevice-dev libavfilter-dev 


I'm trying to compile a cpp code which uses libavcodec:

 #include <libavcodec/avcodec.h>

I tried all variations of

find_package()

with names like ffmpeg for which I get

CMake Warning at CMakeLists.txt:17 (find_package):
  By not providing "Findffmpeg.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "ffmpeg", but
  CMake did not find one.

  Could not find a package configuration file provided by "ffmpeg" with any
  of the following names:

    ffmpegConfig.cmake
    ffmpeg-config.cmake

  Add the installation prefix of "ffmpeg" to CMAKE_PREFIX_PATH or set
  "ffmpeg_DIR" to a directory containing one of the above files.  If "ffmpeg"
  provides a separate development package or SDK, be sure it has been
  installed.

By the way, I did sudo apt install -y ffmpeg before all that.

I'm compiling with

add_executable(my_executable ${sources})

Minimal working example

CMakeLists.txt

cmake_minimum_required(VERSION 3.1.0)

project(hello)

find_library(AVCODEC_LIBRARY avcodec)

add_executable(hello main.cpp)

target_link_libraries( hello PRIVATE ${AVCODEC_LIBRARY})

main.cpp

#include <iostream>
using namespace std;

int main() 
{
    cout << "Hello, World!";
    return 0;
}

Output:

lz@vm:~/mcve$ cmake .
-- The C compiler identification is GNU 7.2.0
-- The CXX compiler identification is GNU 7.2.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
AVCODEC_LIBRARY
    linked by target "hello" in directory /home/lz/mcve

-- Configuring incomplete, errors occurred!
See also "/home/lz/mcve/CMakeFiles/CMakeOutput.log".

解决方案

This is what was missing (even though libavcodec appeared in some folders of my system)

sudo apt install -y libavcodec-dev libavformat-dev libavdevice-dev libavfilter-dev

这篇关于在Cmake中链接libavcodec,find_library不适用于任何库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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