使用MinGW编译OpenTTD

出自OpenTTD 运输大亨

跳转到: 导航, 搜索

Compiling on MinGW 使用MinGW编译 Introduction 前言

This page contains guidelines for compiling OpenTTD in Win32 with MinGW. 本页面为在Win32环境下使用MinGW编译Openttd所作的指导。 information 信息

Source tested: OTTD trunk at revision 9788. 源代码测试:OTTD trunk 9788版(注:ottd 0.6.0版可以使用)

Packages used here: 所需软件

MinGW-5.1.3 
binutils-2.16.91-20060119-1
gcc-core-3.4.2-20040916-1
gcc-g++-3.4.2-20040916-1
mingw-runtime-3.12 w32api-3.9

mingw的安装程序会自动下载最新的相关文件来下载(连接的国外网站,电信速度很慢,强烈BS),原文中的文件已经过时,新的文件不影响使用。当然,你也可以手动下载最新的相关文件,例如gcc-core-3.4.5-20060117-1.tar.gz,放入mingw- 5.1.3.exe同一目录下,程序会自动安装,免去下载了。在线下载容易出问题,我安装了好几回。 MSYS-1.0.10

wget-1.9.1 (from mingwPORT mingwPORTor sources) -> Needed to install mingwPORTs 

需要安装mingwports zlib-1.2.3 (from mingwPORT or Sources) libpng-1.2.8 (from mingwPORT or sources)

SVN, to retrieve latest OTTD code.
svn,用来获得最新的ottd源代码。可选择安装,因为可以手动去官方nightly下载打包好的源代码。原文作者可能不需要使用freetype,而中文编译需要下载freetype文件。

All downloads combined is approximately 30MB and then you can expect another ~30MB of OTTD sourcecode. Expect a disk usage of about 250MB. 以上所下载的软件约需30MB空间,而你需要约30MB的空间以放置源代码。所以保证磁盘空间大于250MB。

[edit] Setting up MinGW 安装MinGW Please note that MinGW should be installed to a directory path that doesn't contain any spaces. 请注意,MinGW的目录名中不能包含空格。

Run the MinGW 5.1.3 install file. 运行MinGW5.1.3安装文件 On the install, select Candidate, then select the Minimal install plus the g++ compiler.
在安装过程中,选择Candidate,然后选择最小安装,并且把g++ compile勾选上一起安装。
[edit] Setting up MSYS 

安装MSYS Please note that MSYS should be installed to a directory path that doesn't contain any spaces.

请注意,MSYS的目录名不能包含空格。
Run the MSYS install. You will see the following messages after GUI: 

运行MSYS安装程序,你可以在安装窗口中看到以下信息: This is a post install process that will try to normalize between your MinGW install if any as well as your previous MSYS installs if any. I don't have any traps as aborts will not hurt anything. (不明白,以后慢慢翻译)

Do you wish to continue with the post install? [yn ]Input "y". 

你是否愿意继续安装?[yn] 输入“y”。

Do you have MinGW installed? [yn ]Input "y".
你是否安装了MinGW?[yn]输入y Please answer the following in the form of c:/foo/bar.Where is your MinGW installation?

请输入mingw目录,例如:c:/foo/bar (必须为"/",否则无法识别) Input your MinGW installation path. If you mistyped it, the best solution for newbies is to re-install MSYS. 输入mingw安装目录,如果输入错误,最好是重新安装一次msys。

[edit] Install SVN 安装svn Create a new folder called local in the directory where MSYS is installed. 在msys的安装目录下,新建一个目录名为local 的目录。

Unzip the folders bin, iconv, licenses, share from the SVN zip file and place into the new folder created in step 1 

解压svn压缩文件中:bin,iconv,licenses及share目录放入第一步中创建的目录里。

[edit] Testing the MinGW installation 测试mingw安装环境 Run MSYS. 运行msys ,即点击X:\msys\msys.bat Run the following commands:

在msys命令行中输入以下命令: make -v gcc -v svn help (svn为可选择安装,安装了可以看看。我是没装)
They should output something. Check if something goes wrong. 

屏幕上会输出一些东西,请查检是否有错误。

[edit] Compiling wget

编译wget Place wget-1.9.1-mingwPORT.tar.bz2 in a folder (e.g. /home). 将wget-1.9.1-mingwPORT.tar.bz2 放入某个目录(如:/home)。 Start MSYS. 运行msys。 Make sure you are in the same directory where you placed the file and Run: 请确定你当前目录与所放文件在同一目录并运行以下命令:(由根目录进入home目录使用cd /home命令) tar -xvjf wget-1.9.1-mingwPORT.tar.bz2 mkdir -p /usr/local/bin cd wget-1.9.1/mingwPORT cp wget.exe /usr/local/bin mkdir /usr/src ./mingwPORT.sh Answer the questions by pressing enter. 运行成功后,一路按回车(除了freetype的安装) It will download wget sources, compile and install them for you. 程序会自动下载源代码并安装。 Remove the temporary wget: 删除wget临时文件: /usr/local/bin/wget.exe

[edit] Compiling zlib 编译zlib Place zlib-1.2.3-mingwPORT-1.tar.bz2 in a folder (e.g. /home) 将Place zlib-1.2.3-mingwPORT-1.tar.bz2放入某个目录(如:/home)。 Start MSYS. 运行msys Make sure you are in the same directory where you placed the file and Run: 请确定你当前目录与所放文件在同一目录并运行以下命令:(返回上层目录使用cd ..) tar -xvjf zlib-1.2.3-mingwPORT-1.tar.bz2 cd zlib-1.2.3/mingwPORT ./mingwPORT.sh Answer the questions by just pressing enter. 运行成功后,一路按回车。 It will download zlib sources, compile and install them for you. 程序会自动下载源代码并安装。 Now its time to make the files available where they are needed. Run: 现在运行以下命令以便zlib可以使用: mkdir /usr/local/include mkdir /usr/local/lib cp /mingw/include/zlib.h /usr/local/include cp /mingw/lib/libz.a /usr/local/lib[edit] Compiling pnglib

Place libpng-1.2.8-mingwPORT.tar.bz2 in a folder (e.g. /home) 将 libpng-1.2.8-mingwPORT.tar.bz2 放入某个目录(如:/home)。 Start MSYS. 运行msys Make sure you are in the same directory where you placed the file and Run: 请确定你当前目录与所放文件在同一目录并运行以下命令:(返回上层目录使用cd ..) tar -xvjf libpng-1.2.8-mingwPORT.tar.bz2 cd /home/libpng-1.2.8/mingwPORT ./mingwPORT.sh Answer the questions by just pressing enter. 运行成功后,一路按回车。 It will download pnglib sources, compile and install them for you. 程序会自动下载源代码并安装。

编译freetype: 将freetype-2.1.9-mingwPORT.tar.bz2放入某个目录中(如:/home),在同一目录下,运行以下命令: tar -xvjf freetype-2.1.9-mingwPORT.tar.bz2 cd /home/freetype-2.1.9/mingwPORT ./mingwPORT.sh 第一个问题按回车,第2个问题按回车默认是选择镜像网站下载:输入3,选择台湾(看个人网速,再次BS电信)。后面全按回车了。程序也会自动下载安装了。

[edit] Getting the source 获得源代码 There are several ways to obtain the source: 有以下几个途径可以获得源代码:

This is one way: 一:

Start MSYS. 运行msys Run: 输入以下命令: mkdir /home/ottdsrc cd /home/ottdsrc svn checkout svn://svn.openttd.com/trunk

edit] Compiling OTTD 编译ottd If you cannot compile, don't panic. Sometimes it may be due to coding errors. 如果你无法开始编译,别惊慌,可能是源代码有错误。 Start MSYS. 运行msys。 Run: 输入以下命令 cd /home/ottdsrc/trunk 注意,这里的命令是指安装了svn并按上一步建立了/home/ottdsrc目录并使用svn获得源代码的情况下的目录。如果是手动下载的,请输入其它的目录。 ./configure make Some warnings may be shown, but they usually do not matter. 一些警告可能会出现,但通常情况下不会有太大的影响。 The compiling is complete when the openttd.exe file is made. It will be copied to the ./bin subfolder. 编译完成后,ottd.exe会自动生成在./bin 目录中。

[edit] Testing OTTD 测试ottd Copy the following files from (TTD)\data\ to (OTTD)\data\: 拷贝以下文件到(ottd)\data\目录下: sample.cat trg1r.grf trgcr.grf trghr.grf trgir.grf trgtr.grf Copy the folder (TTD)\gm to (OTTD)\gm (Optional: only if you want music) 拷贝音乐文件到(ottd)\gm目录下,如果你想听音乐的话。 Run openttd.exe. 双击openttd.exe Enjoy! 开始享受吧。