如何在vc6下编译x264

来源:互联网 发布:c语言primer plus 编辑:程序博客网 时间:2024/05/19 15:20

如何在vc6下编译x264

Peter Lee(lspbeyond@sohu.com)

 

==============================================

NOTE: 目前我已提供x264vc6,vc7下成功编译的源代码,每周更新一次。

大家可以直接下载使用,省去一些麻烦。

http://lspbeyond.go1.icpcn.com/x264/index.htm

==============================================

1、下载x264

x264的主页:http://videolan.org/

x264是用版权控制工具CVS进行更新的,其主页上不提供源码压缩包,所以我们要用专用的工具下载。

工具名:TortoiseSVN

使用方法:如图1所示。其中下载地址为:svn://svn.videolan.org/x264/trunk/

1

 

2、准备编译环境所需文件

note:23部分参考了《How to Compile XviD with Microsoft Visual C++ 6.0》一文的内容

1) Service Pack 5 for Visual Studio 6 -http://msdn.microsoft.com/vstudio/downloads/updates/sp/vs6/sp5/default.asp
The service pack contains all the latest bug fixes for Visual C++ 6.0 as well as updates to essential libraries. You can download the service pack or order it on CD from the Microsoft Developers Network (MSDN) by clicking the link above.
vc6补丁,所选的语言和VC的语言一致就可以了

2) Visual C++ 6.0 Processor Pack - http://msdn.microsoft.com/vstudio/downloads/tools/ppack/default.aspx
The processors pack adds support for Intel's SSE, SEE2 and AMD's 3DNow! instructions. 
支持处理器多媒体汇编指令的补丁

3) NASM - the famous Netwide Assembler - http://sourceforge.net/projects/nasm/
Xvid uses NASM to "compile" the code written in assembly language (the *.asm files). Download the Win32 binary.
x264同样会用到这个编译器

4) DirectX 9.0 SDK - http://msdn.microsoft.com/library/default.asp?url=/downloads/list/directx.asp
To build the DirectShow filter, you need the DirectX SDK (Software Development Kit). Unfortunately for dial-up users, the ~200MB DirectX SDK is no longer available on CD.
编译x264中的vfw工程时要用到

 

3、设置编译环境

1) Installing Service Pack 5

The Service Pack is easy to install since it comes with an installer. The installer's filename is "setupsp5.exe". Just find the file and double-click it.
自解压后,运行setupsp5.exe

2) Installing Visual C++ Processor Pack

Double-click "vcpp5.exe" to install.

3) Installing and Configuring NASM

Xvid expects the filename to be "nasm.exe" (probably because all other versions except the Win32 version has that name). For some reason, the Win32 version NASM has a filename of "nasmw.exe." I recommend making a copy of "nasmw.exe" and renaming it "nasm.exe."
文件名一定要改成nasm.exe ,拷贝到Microsoft Visual Studio6/vc98/bin下即可

4) Installing and Configuring the DirectX SDK

 

4x264程序改动

1)、文件格式转换unix->dos: build/win32下的三个工程文件。

网上下个名为unix2dos的小工具,或用写字板另存为的方法。

 

2)、在common.h头部加入#define HAVE_STDINT_H 1

 

3)、将x264.c中的含strncasecmp的代码部分进行注释或改写

strncasecmp函数的功能是不考虑大小写的情况,比较两个字符串,vc6下没有这个库函数。

strncasecmp部分的代码都是用来检验输入参数的文件扩展名的,注释后表示这一功能丧失,故建议改写。


1.   所用的代码为2006726日用TortiseSVN从官方网站站上下载;

2.   编译环境完全按照李世平老师所讲的;

3.   build\win32目录下的所有文件(共8个文件)用写字板打开后按照原文件名保存;

4.   用写字板将libx264.dsp文件打开并删除376~379行的内容后保存,即删除:     # Begin Source File SOURCE="..\..\common\i386\dct-c.c"    # End Source File

             用同样的方法将libx264.vcproj打开并删除1058~1085行内容后保存,即删除:

    <File<File  RelativePath="..\..\common\i386\dct-c.c">
     <FileConfiguration
      Name="Release|Win32">
      <Tool
       Name="VCCLCompilerTool"
       Optimization="2"
       AdditionalIncludeDirectories=""
       PreprocessorDefinitions=""/>
     </FileConfiguration>
     <FileConfiguration
      Name="Debug|Win32">
      <Tool
       Name="VCCLCompilerTool"
       Optimization="0"
       AdditionalIncludeDirectories=""
       PreprocessorDefinitions=""
       BasicRuntimeChecks="3"/>
     </FileConfiguration>
     <FileConfiguration
      Name="Release64|Win32">
      <Tool
       Name="VCCLCompilerTool"
       Optimization="2"
       AdditionalIncludeDirectories=""
       PreprocessorDefinitions=""/>
     </FileConfiguration>
    </File>

5.接下来就可以编译了:但在编译时会出现两处“L”和“ULL”有问题的地方(只是在VC6中出现这种问题,VC7VC8中不会出现这种问题),就直接将“L”和“ULL”删除就行(因为数据类型问题)。即:common\divdict.c615 *(uint64_t*)(edge+24) = SRC(7,-1) * 0x0101010101010101ULL;改为 *(uint64_t*)(edge+24) = SRC(7,-1) * 0x0101010101010101;matroksa.c中的431 if (delta > 32767ll || delta < -32768ll)改为 if (delta > 32767 || delta < -32768)

通过以上方法就可直接在官方网站下载代码自己编译了。如果大家在编译过程中有什么问题或学习经验,请贴出来共同分享。



   由于x264的开发平台不是windows,所以在Windows上用VC编译器来编译x264总是不能一次成功,现将在编译过程中的常见错误总结如下,希望能节省初学者的时间。

    x264在VC环境中的编译指南下载地址:x264源代码(含VC编译指南)

    以下错误是在vc71下试验的错误情况,vc6下会有稍许差别,但也类似。

[1] x264路径带空格

错误:

正在执行自定义生成步骤

nasm: error: more than one input file specified

type `nasm -h' for help

Project : error PRJ0019: 工具从"正在执行自定义生成步骤"

特征:

nasm出现错误

原因:

你的x264文件夹的路径中有空格,如下所示:

D:\program files\x264-051226

nasm.exe把空格前的字符串作为路径,从而导致了错误。

[2] nasm未安装

错误:

Assembly "..\..\common\i386\predict-a.asm"

'nasm' 不是内部或外部命令,也不是可运行的程序

或批处理文件。

Error executing c:\windows\system32\cmd.exe.

特征:

'nasm' 不是内部或外部命令,也不是可运行的程序

原因:

没有安装nasm

解决:从本站下载nasm.exe(098版本),拷贝到vc安装目录的bin文件夹下就可以了。

[3] vc6没有打补丁

错误:

common.h(69) : fatal error C1600: unsupported data type

common.h:error c2485:'align':unrecognized externded attribute syntax error:'c'

特征:

数据类型不支持

原因:

vc6没有安装sp5vcpp

[4] .c文件按没有包含到工程中

错误:

x264.obj : error LNK2019: 无法解析的外部符号 _mk_createWriter ,该符号在函数 _open_file_mkv 中被引用

x264.obj : error LNK2019: 无法解析的外部符号 _mk_addFrameData ,该符号在函数 _write_nalu_mkv 中被引用

x264.obj : error LNK2019: 无法解析的外部符号 _mk_startFrame. ,该符号在函数 _write_nalu_mkv 中被引用

x264.obj : error LNK2019: 无法解析的外部符号 _mk_writeHeader ,该符号在函数 _write_header_mkv 中被引用

x264.obj : error LNK2019: 无法解析的外部符号 _mk_setFrameFlags ,该符号在函数 _set_eop_mkv 中被引用

x264.obj : error LNK2019: 无法解析的外部符号 _mk_close ,该符号在函数 _close_file_mkv 中被引用

特征:

link错误,出现无法解析的外部符号。

原因:

.c文件按没有包含到工程中。这是因为x264win32下的vc工程没有和x264同步更新所致,当x264加入了新的源文件,而vc工程中没有包含进来,就会有这样的错误。像上例就是因为matroska.c没有包含到工程中所致。

Ps: .h文件没有包含的工程中,一般不会出错,但建议还是包含进来,养成好习惯嘛。

[5]安装了intel编译器(未试验)

错误:

LINK : fatal error LNK1104: cannot open file "libm.lib"

Error executing link.exe.

特征:

libm.lib link错误

原因:

可能是安装了intel c++ complier

[6] .asm文件没有设置自定义编译选项

错误:

libx264.lib(cpu.obj) : error LNK2019: 无法解析的外部符号 _x264_cpu_cpuid ,该符号在函数 _x264_cpu_detect 中被引用

libx264.lib(cpu.obj) : error LNK2019: 无法解析的外部符号 _x264_cpu_cpuid_test ,该符号在函数 _x264_cpu_detect 中被引用

libx264.lib(cpu.obj) : error LNK2019: 无法解析的外部符号 _x264_emms ,该符号在函数 _x264_cpu_restore 中被引用

特征:

容易和没有包含.c文件的错误混淆,其特征就是出现的外部符号都是汇编文件中的。

原因:

每个.asm文件都有自定义的编译选项。

解决(针对本例):vc下,project setting,选中cpu-a.asm这个文件,然后将其commands设置为:

nasm -f win32 -DPREFIX -o $(IntDir)\$(InputName).obj $(InputPath)