clockid_t has not been declared问题

今天学FFmpeg开发,第一项目就出现问题。

按照一般的操作,在*.pro文件中添加头文件,库文件。

1
2
3
4
5
6
7
8
unix{

INCLUDEPATH += /usr/include

LIBS += -L/usr/lib \
-lavcodec -lavdevice -lavfilter -lavformat \
-lavutil -lpostproc -lswresample -lswscale
}

linux下的FFmpeg头文件就在/usr/include目录下。

在*.h文件中添加

1
2
3
4
5
6
7
extern "C"
{
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
#include "libswscale/swscale.h"
#include "libavdevice/avdevice.h"
}

编译报错:/usr/include/pthread.h:775: error: ‘clockid_t’ has not been declared

如果直接改成

1
2
3
4
5
6
7
8
9
unix{

INCLUDEPATH += /usr/include/libavcodec \
.....

LIBS += -L/usr/lib \
-lavcodec -lavdevice -lavfilter -lavformat \
-lavutil -lpostproc -lswresample -lswscale
}

那么就会报错:stdlib.h找不到

可以看出这是由于/usr/include目录下头文件冲突造成的。

解决方法就是直接包含完整路径。

1
2
3
4
5
6
extern "C"{
#include "/usr/include/libavcodec/avcodec.h"
#include "/usr/include/libavformat/avformat.h"
#include "/usr/include/libswscale/swscale.h"
#include "/usr/include/libavdevice/avdevice.h"
}

clockid_t has not been declared问题
https://feater.top/linux/clockied_t-has-not-been-declared-error/
作者
JackeyLea
发布于
2021年10月10日
许可协议