https://blog.csdn.net/biezhihua/article/details/52734662
Preface
The two days installed on the Mac mounted a ffmpeg, and created a clion C + + project, in the introduction of FFmpeg as a libraries encountered some problems, recorded. How to install FFmpeg
Please look at this document, not much: MAC INSTALL FFMPEG
clion How Project introduces Lib Setup 1
After installing the FFmpeg:
/usr/local/cellar/ffmpeg/3.1.4/include
/usr/local/cellar/ffmpeg/3.1.4/lib
The directory is copied to the project root (in fact, it can not be copied, directly into the CMakeLists.txt directly into the absolute Path can also) Setup 2
Introduction of include and Lib in CMakeLists.txt
There are several ways to use the CMake: Include_directories is used to introduce the. h file link_directories used to tell the project Lib the location target_link_libraries the Lib link into the project
Where Target_link_libraries's position is to be placed after add_executable.
Also note that the first parameter of Target_link_libraries is the project name, which is Project (Ffmpegdemo) in CMakeLists.txt. The Lib name of the target_link_libraries is similar to the position of the lib*.a in LIBAVCODEC.A, that is to say Libavcodec.a's lib name is Avcodec
Example
Include_directories (./include/)
link_directories (./lib/)
set (Source_files main.cpp)
add_executable ( Ffmpegdemo ${source_files})
target_link_libraries (
ffmpegdemo
avcodec
avdevice
avfilter
avformat
avresample
avutil
postproc
swresample
swscale
)
Write a simple sample code to verify that the success was introduced. Note: Because it is a C + + project, the introduction of header files requires extern "C" {}
extern "C" {#include <libavformat/avformat.h> #include <libavcodec/avcodec.h>}
using namespace Std;
int main () {cout << "result" << Endl;
cout << avcodec_configuration ();
return 0; }
Result:
result--prefix=/usr/local/cellar/ffmpeg/3.1.4- -enable-shared--enable-pthreads--ENABLE-GPL--enable-version3--enable-hardcoded-tables--enable-avresample--cc= Clang--host-cflags=--host-ldflags=--enable-opencl--enable-libx264--enable-libmp3lame--enable-libxvid-- Disable-lzma--enable-vda Process finished with exit code 0
copyright notice: This article for Bo Master original article, without Bo Master permission not reproduced. https://blog.csdn.net/biezhihua/article/details/52734662