zl程序教程

您现在的位置是:首页 >  其他

当前栏目

x264代码剖析(四):vs2010编译x264错误集锦

错误代码 编译 剖析 集锦 VS2010 X264
2023-09-14 08:57:58 时间

 

        支持VC++平台的x264的最新版本是x264-20091006,接下来就以该版本为例分析编译运行x264过程中遇到的问题以及解决办法。

 

1、error C2143: syntax error : missing ; before type

 

错误提示:



错误原因:MS的VS编译器对C99标准支持不好,不支持函数当中混合定义、声明变量。

解决办法:在函数开头统一定义变量。

 

示例源码:

static ALWAYS_INLINE int x264_exp2fix8( float x )

 if( x = 512.f/6.f ) return 0;

 if( x = -512.f/6.f ) return 0xffff;

 int i = x*(-64.f/6.f) + 512;

 return (x264_exp2_lut[i 63]+256) (i 6) 8;

}

修改后代码:

static ALWAYS_INLINE int x264_exp2fix8( float x )

 int i; 

 if( x = 512.f/6.f ) return 0;

 if( x = -512.f/6.f ) return 0xffff;

 i = x*(-64.f/6.f) + 512;

 return (x264_exp2_lut[i 63]+256) (i 6) 8;

}

注:x264代码中有十几处类似的错误,只需一一改正过来就可以了。


2、error C2059: syntax error : [

 

错误代码:

static const uint8_t check_mv_lists[X264_MBTYPE_MAX] = {[P_L0]=1, [B_L0_L0]=1, [B_L1_L1]=2};

修改为:

static const uint8_t check_mv_lists[X264_MBTYPE_MAX] ={0,0,0,0,1,0,0,0,1,0,0,0,2,0,0,0,0,0,0};


3、error C2146: syntax error : missing ) before identifier PRIx32

 

错误代码:

fprintf( stderr, "Bad header magic (%"PRIx32" = %s)\n",*((uint32_t*)header), header );

修改为:

fprintf( stderr, "Bad header magic (%ld %s)\n", *((uint32_t*)header), header );


4、error LNK2019: unresolved external symbol _x264_lookahead_init referenced in function _x264_encoder_open_76

 

        这是由于libx264工程没有添加lookahead.c文件,从而缺少几个函数的定义造成的,错误提示如下图:


        

         解决方法:添加lookahead.c进工程,如下图所示:




5、error LNK2019: unresolved external symbol _log2f referenced in function _x264_analyse_init_costs

 

         解决办法:重新定义一下log2f(x)即可,在osdep.h中添加log2f(x)定义,加入的代码如下:

#ifdef _MSC_VER

#define inline __inline

#define strcasecmp stricmp

#define strncasecmp strnicmp

#define snprintf _snprintf

#define fseek _fseeki64

#define ftell _ftelli64

#define isfinite _finite

#define strtok_r strtok_s

#define _CRT_SECURE_NO_DEPRECATE

#define X264_VERSION "" // no configure script for msvc

#define log2f(x) (logf(x)*1.4426950408889634f)

#endif

       截止目前,应该可以把所有的问题都解决了,出现了大家最喜欢的Build succeeded。大笑



        编译成功的源码包下载地址:http://download.csdn.net/detail/frd2009041510/9455143大笑


如果你使用惯了linux,你会对软件包管理、命令行不能自拔。由于mac的底层是类unix系统,也可以配置向linux一样好用。
安装HomeBrew /usr/bin/ruby -e $(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install) 上面必须先有ruby以及其他开发环境支持,建议安装xcode后使用以上命令安装。