vs2005调用ffmpeg库执行av_register_all出错崩溃

今天下载了1.2版本的FFmpeg库,在官方网站有一个链接,可以下载到编译好的windows版本的库。下载下来后,写了一段程序,在main函数中执行到函数av_register_all(),直接崩溃,提示Unhandled exception at 0x00905a51 in main.exe: 0xC000001D: Illegal Instruction,工程是Release版本的,调用代码如下:

#include <stdio.h>

#include <libavformat/avformat.h>
#include <libavutil/dict.h>

int main (int argc, char **argv)
{
    AVFormatContext *fmt_ctx = NULL;
    AVDictionaryEntry *tag = NULL;
    int ret;

    if (argc != 2) {
        printf("usage: %s <input_file>\n"
               "example program to demonstrate the use of the libavformat metadata API.\n"
               "\n", argv[0]);
        return 1;
    }

    av_register_all();
    if ((ret = avformat_open_input(&fmt_ctx, argv[1], NULL, NULL)))
        return ret;

    while ((tag = av_dict_get(fmt_ctx->metadata, "", tag, AV_DICT_IGNORE_SUFFIX)))
        printf("%s=%s\n", tag->key, tag->value);

    avformat_close_input(&fmt_ctx);
    return 0;
}


在Debug模式下正常,后来在发现,只要修改工程属性可以解决这个问题,首先打开工程属性,找到链接项目,在优化中有个引用项,选择保留未引用数据(/OPT:NOREF)即可,我的工程是英文版,截图如下:

Comments are closed.