FFmpeg编译趟坑记录

今天在编写CMake构建FFmpeg的代码工程的时候,发现死活链接库都提示有问题,还有问题就是一添加C++的头文件,就提示ctime::clock_t没有声明等。特此记录一下。

开发环境。

* File   : readme.md
* Author : 小和尚念经敲木鱼
* Email  : null
* Time   : Fri 05 Feb 2021 10:47:17 AM CST
* cmake version : cmake version 3.9.0
* c++   version : (Ubuntu 5.3.1-14ubuntu2) 5.3.1 20160413
* system os     : ubuntu16

1、CMakeLists.txt书写有问题

如果出现如下这种报错,但是自己的开发环境是没有问题的。

/usr/include/c++/4.8/ctime:60:11: error:::clock_t’ has not been declared
   using ::clock_t;
           ^
/usr/include/c++/4.8/ctime:61:11: error:::time_t’ has not been declared
   using ::time_t;
           ^
/usr/include/c++/4.8/ctime:64:11: error:::clock’ has not been declared
   using ::clock;
           ^
/usr/include/c++/4.8/ctime:65:11: error:::difftime’ has not been declared
   using ::difftime;
           ^
/usr/include/c++/4.8/ctime:66:11: error:::mktime’ has not been declared
   using ::mktime;
           ^
/usr/include/c++/4.8/ctime:67:11: error:::time’ has not been declared
   using ::time;
           ^
/usr/include/c++/4.8/ctime:68:11: error:::asctime’ has not been declared
   using ::asctime;
           ^
/usr/include/c++/4.8/ctime:69:11: error:::ctime’ has not been declared
   using ::ctime;
           ^
/usr/include/c++/4.8/ctime:70:11: error:::gmtime’ has not been declared
   using ::gmtime;
           ^
/usr/include/c++/4.8/ctime:71:11: error:::localtime’ has not been declared
   using ::localtime;
           ^
/usr/include/c++/4.8/ctime:72:11: error:::strftime’ has not been declared
   using ::strftime;

或者类似这种报错打印:
FFmpeg编译趟坑记录_第1张图片
最后发现是CMakeLists.txt里面包含头文件写错了。可以参考如下:

FFmpeg 编写CMakeLists.txt时,添加链接头文件参照下面写法,添加到下级目录出错:
原来的写法:
include_directories(
        ${CMAKE_CURRENT_SOURCE_DIR}/inc
        /usr/local/ffmpeg/include/libavformat
       /usr/local/ffmpeg/include/libavcodec
       /usr/local/ffmpeg/include/libavdevice
)
修改成如下方式,通过编译:
include_directories(
          ${CMAKE_CURRENT_SOURCE_DIR}/inc
          /usr/local/ffmpeg/include/
)

2、FFmpeg头文件添加的有问题

如果出现类似添加so库了,但是识别不了FFmpeg接口函数的时候,编译打印如下。

CMakeFiles/SampleApp.dir/src/main.cpp.o:在函数‘FFmpegEncoderFrame::~FFmpegEncoderFrame()’中:
main.cpp:(.text+0x77):对‘avcodec_close(AVCodecContext*)’未定义的引用
main.cpp:(.text+0x94):对‘avcodec_free_context(AVCodecContext**)’未定义的引用
main.cpp:(.text+0xb1):对‘av_frame_free(AVFrame**)’未定义的引用
main.cpp:(.text+0xce):对‘av_packet_free(AVPacket**)’未定义的引用
main.cpp:(.text+0xeb):对‘sws_freeContext(SwsContext*)’未定义的引用

出现这种打印,应该是头文件包含的方式出现了问题,可以尝试以下的两种方式重新添加一下头文件。

1、方案1 以C语言方式包含头文件
extern "C"
{
	#include 
	#include 
	#include 
}
2、方案2 包含头文件的绝对路径
extern "C"
{
	#include "/usr/local/ffmpeg/include/libavcodec/avcodec.h"
	#include "/usr/local/ffmpeg/include/libavutil/opt.h"
	#include "/usr/local/ffmpeg/include/libavutil/imgutils.h"
	#include "/usr/local/ffmpeg/include/libswscale/swscale.h"
}

你可能感兴趣的:(FFmpeg学习专栏,ffmpeg,linux)