C++ 在Cmake中链接libavcodec,查找#u library won';我不与任何图书馆合作
我正在尝试编译一个使用libavcodec的cpp代码:C++ 在Cmake中链接libavcodec,查找#u library won';我不与任何图书馆合作,c++,cmake,compilation,C++,Cmake,Compilation,我正在尝试编译一个使用libavcodec的cpp代码: #include <libavcodec/avcodec.h> 用像ffmpeg这样的名字 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 configur
#include <libavcodec/avcodec.h>
用像ffmpeg
这样的名字
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.
顺便说一句,在这之前我安装了sudo apt-y ffmpeg
我正在和你一起编译
add_executable(my_executable ${sources})
最小工作示例
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;
}
这就是缺少的内容(即使libavcodec
出现在我的系统的一些文件夹中)
您确定
ffmpeg
附带了CMake包定义吗?您是否尝试手动指定库?@πάνταῥεῖ 我认为ffmpeg不支持cmake。我应该怎样用手做?我认为使用add_libraries()
maybe?@πάντα是不可能的ῥεῖ 我认为add_library(libavcodec)添加了该库,但当它尝试加载该库的.h时,编译失败。这是否意味着库没有加载,或者我还需要为它指向include路径?我不想添加我的个人包含路径,我希望它是自动的。我想这里还需要include\u目录。阅读CMake文档。
#include <iostream>
using namespace std;
int main()
{
cout << "Hello, World!";
return 0;
}
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".
sudo apt install -y libavcodec-dev libavformat-dev libavdevice-dev libavfilter-dev