有人能从gcc中提供这些错误的线索吗?

有人能从gcc中提供这些错误的线索吗?,c,gcc,ffmpeg,libavformat,C,Gcc,Ffmpeg,Libavformat,我有以下代码: #include <stdlib.h> #include <string.h> #include <libavcodec/avcodec.h> #include <libavutil/opt.h> #include <libavformat/avformat.h> int main(int argc, char **argv) { avcodec_register_all(); av_register_

我有以下代码:

#include <stdlib.h>
#include <string.h>
#include <libavcodec/avcodec.h>
#include <libavutil/opt.h>
#include <libavformat/avformat.h>

int main(int argc, char **argv)
{
    avcodec_register_all();
    av_register_all();

    struct AVCodecTag * const *avctag;
    AVOutputFormat *outputFormat = NULL;

    const char *file = "file.mp4";
    outputFormat = av_guess_format(0, file, 0);

    if( ! outputFormat)
    {
        printf ("No container found\n");
        exit (1);
    }
    printf("%s %d\n",outputFormat->long_name,outputFormat->video_codec);

    avctag = outputFormat->codec_tag[0];
    printf("%d\n",avctag->id);
}
但它也发出了警告:

warning: assignment from incompatible pointer type [-Wincompatible-pointer-types]
  avctag = outputFormat->codec_tag;
AVOutputFormat:codec_标签根据文档定义为:

结构AVCodecTag*常量*

这正是我在上面定义的指针。有人能告诉我为什么我会得到警告和错误吗


非常感谢

声明的指针
avctag
,就像指向常量指针的指针一样

struct AVCodecTag * const *avctag;
所以这个声明

printf("%d\n",avctag->id);
avctag = outputFormat->codec_tag[0];
这是无效的

您需要检查这个语句中右边表达式的类型

printf("%d\n",avctag->id);
avctag = outputFormat->codec_tag[0];

outputFormat->codec\u标记[0]
的类型是什么?

声明的指针
avctag
,就像指向常量指针的指针一样

struct AVCodecTag * const *avctag;
所以这个声明

printf("%d\n",avctag->id);
avctag = outputFormat->codec_tag[0];
这是无效的

您需要检查这个语句中右边表达式的类型

printf("%d\n",avctag->id);
avctag = outputFormat->codec_tag[0];

outputFormat->codec\u标记[0]
的类型是什么?

声明中的
*
太多了

outputFormat->codec_标记
struct-AVCodecTag*const*
,这意味着
outputFormat->codec_标记[0]
只是
struct-AVCodecTag-const*

或者你可以做的其他选择

avctag = outputFormat->codec_tag;
printf("%d\n",avctag[0]->id);

您的声明中有太多的
*

outputFormat->codec_标记
struct-AVCodecTag*const*
,这意味着
outputFormat->codec_标记[0]
只是
struct-AVCodecTag-const*

或者你可以做的其他选择

avctag = outputFormat->codec_tag;
printf("%d\n",avctag[0]->id);


即使删除“const”一词,我也会收到相同的警告和错误消息。。。不过还是谢谢你的回复。@GiuTor删除限定符const并不会使这个双指针变成单指针。你似乎不明白你在这个项目中做什么。您需要研究文档。这就是我所做的,在文档中,AVOutputFormat结构中的字段codec_标记声明为struct AVCodecTag*const*@GiuTor您使用的是avctag=outputFormat->codec_标记[0];但是警告是关于语句avctag=outputFormat->codec\u标记的;如何理解这一点?你在这句话里做什么?我想把所有的编解码器id链接到一个给定的容器。我给出了我正在使用的源代码。你编译过吗…?即使删除“const”这个词,我也会得到同样的警告和错误信息。。。不过还是谢谢你的回复。@GiuTor删除限定符const并不会使这个双指针变成单指针。你似乎不明白你在这个项目中做什么。您需要研究文档。这就是我所做的,在文档中,AVOutputFormat结构中的字段codec_标记声明为struct AVCodecTag*const*@GiuTor您使用的是avctag=outputFormat->codec_标记[0];但是警告是关于语句avctag=outputFormat->codec\u标记的;如何理解这一点?你在这句话里做什么?我想把所有的编解码器id链接到一个给定的容器。我给出了我正在使用的源代码。你编译了吗…?好的,删除一个*只会得到一个错误,对我来说更糟糕的是:错误:在printf行中取消引用指向不完整类型“const struct AVCodecTag”的指针,这表明您没有包含定义
struct AVCodecTag
是什么的正确标题…或者可能是需要删除的另一个
*
。我包括libavformat.h。此处第521行定义了AVCodecTag错误:未定义类型“struct avcodeTag”printf的使用无效(“%d\n”,avctag[0]->id);^enum_codec.c:57:22:错误:取消引用指向不完整类型“struct AVCodecTag”行521的指针不会定义
struct
-它声明了一个名为
codec_tag
的变量。我检查了-它肯定根本没有在该文件中定义-您需要阅读文档/标题并找到正确的文档/标题确定,删除一个*只会得到一个错误,对我来说更糟糕的是:错误:在printf行中取消引用指向不完整类型“const struct AVCodecTag”的指针,这表明您没有包含定义
struct AVCodecTag
是什么的正确标题…或者可能是需要删除的另一个
*
。我包括libavformat.h。此处第521行定义了AVCodecTag错误:未定义类型“struct avcodeTag”printf的使用无效(“%d\n”,avctag[0]->id);^enum_codec.c:57:22:错误:取消引用指向不完整类型“struct AVCodecTag”行521的指针不会定义
struct
-它声明了一个名为
codec_tag
的变量。我检查过了-它肯定根本没有在该文件中定义-您需要阅读文档/标题并找到正确的文档/标题