总有人说最新的版本 编译不过,搞的群、 论坛里到处都是这种求助贴。建议斑竹把这个解决办法放到醒目的位置,以减少噪音。

科普开始

1、编译问题
由于MS的VS编译器对C99标准支持不好,不支持函数当中混合定义、声明变量。
解决办法:在函数开头统一定义变量

e.g

编译不过
void funA() {                            void funA() {
int i,j;                                     int i,j,x;
i = 0;          ========>       i = 0;
int x = 0;                                   x = 0;
}                                               }

2、链接问题

libx264.lib(encoder.obj) : error LNK2019: 无法解析的外部符号 _x264_lookahead_init,该符号在函数 _x264_encoder_open_75 中被引用
1>libx264.lib(encoder.obj) : error LNK2019: 无法解析的外部符号 _x264_lookahead_is_empty,该符号在函数 _x264_encoder_encode 中被引用
1>libx264.lib(encoder.obj) : error LNK2019: 无法解析的外部符号 _x264_lookahead_get_ frames,该符号在函数 _x264_encoder_encode 中被引用
1>libx264.lib(encoder.obj) : error LNK2019: 无法解析的外部符号 _x264_lookahead_put_frame,该符号在函数 _x264_encoder_encode 中被引用
1>libx264.lib(encoder.obj) : error LNK2019: 无法解析的外部符号 _x264_lookahead_delete,该符号在函数 _x264_encoder_close 中被引用
1>libx264.lib(analyse.obj) : error LNK2019: 无法解析的外部符号 _log2f,该符号在函数 _x264_mb_analyse_load_costs 中被引用

由于最近x264_param中新添了lookahead,而对应Win32工程是没有及时更新。
把encoder/lookahead.c添加到工程里(和encode.c放在一起)即可。

error LNK2019 unresolved external symbol _log2f
另外,如果最后出现error LNK2019 unresolved external symbol _log2f, osdep.h 里定义一下log2f( 不知道性能如何) :

#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
或 :
#define log2f(x)     ((float)log((double)(x)))/(log((double)2))