如何在Windows中安装Wt

人盡茶涼 提交于 2019-12-09 13:57:09

来自:http://redmine.webtoolkit.eu/projects/wt/wiki/Installing_Wt_on_MS_Windows

Installing Wt on MS Windows

原文拷贝,锚链不要点 :-)

This HOWTO assumes you have a clean Windows system and want to use Wt 2.1 or newer series. We start with the download of the compiler and system libraries. We continue to explain where the dependency libraries can be found and how they are installed. Then the configuration of Wt is covered, and finally we build Wt and run the examples.

这个安装文档假设Windows系统是干净的。我们首先要下载编译器和系统需要的库。按这个说明的步骤完成后,我们就可以跑起Wt的例程了。

Unlike Linux distributions, Windows has no easy package managers for developers. To avoid that you're compiling dependencies for half a day before you can use Wt, we strongly reduced the minimal dependencies that Wt requires. Since Wt 2.1, Boost and cmake are the only required dependencies. We will explain two approaches to set up your environment: the quick method, using binary packages, and the thorough method, in which you compile more dependencies, but which will also result in a Wt that supports compression, SSL, etc.

与Linux发行版不同,Windows没有方便实用的包管理器。所以为了避免大家不在安装依赖库方面费时太多,我们已经将Wt的依赖库减少到最小。 Wt2.1起,Wt必须的依赖库只有 Boost和cmake。

These instructions have been tested both on Windows XP and Windows Vista. These instructions are valid for all 2.1 and newer versions of Wt.

Setting up your compiler¶〔安装编译器〕

You need Microsoft Visual Studio 2005 or newer, Professional or Express Edition (C++). The difference is that the former is payware, whereas the latter is a free reduced version of MSVC. The good news is that the Express Edition is perfect to compile Wt.

先要安装C++编译器,呵呵,就是 VS2005或更高版

For more information about the compiler, see Installing MSVC.

The Quick Method¶〔快速安装〕

The quick method installs Wt without any optional components (compression-over-HTTP and support for HTTPS)

快速安装只安装了Wt,没有太多附加的、可选的组件,实现了compression-over-HTTP and support for HTTPS。

Download Dependencies¶〔下载依赖库〕

  • Download the BoostPro installer for version 1.36 or newer from boost-consulting (you might need to register in order to download the BoostPro installer). Run it, and install all types for all libraries for the correct version of your MSVC compiler at a location of your choice.
  • 下载 BoostPro安装器 >1.36,运行安装需要的库,注意所需库应结合 MSVC编译器的版本来考察。
  • Download the cmake 2.6 (cmake > 2.4.6 required) Windows Installer. Run the installer to install cmake.
  • 下载 cmake 2.6 安装器,运行以安装 cmake。
  • Download Wt from the download page. Unzip it somehwere (c:/projects/witty/wt-2.x.x).
  • 下载Wt包,解压止相应目录如,c:/projects/witty/wt-x.x.x

Configuring Wt¶〔配置Wt〕

  • Start cmake from the Start->CMake menu
  • 启动 cmake
  • Where the source code is: c:\projects\witty\wt-2.x.x
  • 告诉 cmake 我们 wt 源文件目录,如c:\projects\witty\wt-2.x.x
  • Where to build the binaries: c:\projects\witty\wt-2.x.x\build (or whatever, but choose something different than the source directory)
  • 告诉cmake 我们编译目标目录,如 c:\projects\witty\wt-2.x.x\build
  • Click Configure
  • 以上完成后,点击 Configure
  • Select Visual Studio 8 2005 or 2008
  • 选择 VS 的版本
You will probably get errors about Boost not being found. That is normal, as you did not yet tell where the library is located. Set this variables:

这个过程中,我们很可能会得到关于Boost库无法找到的报错信息,这是正常的,因为我们还没有告诉 cmake 我们Boost库的位置。设置如下:
  • BOOST_DIR = c:/Program Files/boost/boost_1_36_0 (adapt for your version)

Another error you might encounter in CMake is "The C compiler "cl" is not able to compile a simple test program." This means that your Visual Studio won't find 'cmd' as it isn't configured correctly.

另一个可能的错误是“The C compiler "cl" is not able to compile a simple test program.”,这说明我们的VS找不到 cmd 。

What you must do is change MSVS options (Tools menu > Options > Project and Solutions > VC++ Directories) to ensure that

这样,我们需要修改 并 确保 MSVS的配置选项正确,Tools menu > Options > Project and Solutions > VC++ Directories:

  • $(SystemRoot)
  • $(SystemRoot)\System32
  • $(SystemRoot)\System32\wbem
  • are specified BEFORE $(PATH).

Press 'Configure' again. A few messages about the FCGI and wthttpd connector may pop up; click Ok (in cmake 2.8, this button is called 'Generate'). A few new configuration fields (in red) will have popped up; leave them unchanged and press 'Configure' once more. If all went well, you have now no red fields left and the configuration is complete. Press 'Ok' and your MSVC solution files will be generated.

配置好后,再点击 “Configure”,随后会出现 关于 FCGI 和 wthttpd 连接器 的对话框弹出,视应用情况选择。另外,一些新的设置选项(字段)也将弹出,可以不理会,继续点“Configure”。如果一切顺利,配置就此完成,点“OK”,我们相关的 MSVC 文件会生成。

Compiling Wt¶〔编译 Wt〕

Open the WT.sln solution in the 'Where to build the binaries' directory of the previous step. Press F7, or select the projects you want to build manually. You should not get any compile or link errors.

在 VS 中 打开 WT.sln文件,按下 F7,这个过程不应有编译错误和链接信息。

Running the examples¶〔运行wt示例〕

In the MSVC IDE Right-click on the example project you want to run, and select 'Properties'. In Configuration Properties->Debugging, set the Command Arguments to

在 MSVS IDE中,右键点击我们希望运行的例子项目,对话框中选择 “Properties”,在配置属性中点击 Debugging,并把命令参数设置为:

--http-address=0.0.0.0 --http-port=8080 --deploy-path=/hello --docroot=.

Wt builds static versions of all libraries by default and links against static boost libraries by default. If you would choose to build dynamic libraries in the future (see remarks at the bottom of this page), the easiest way to locate the dependency dlls, is to append their location to the PATH variable. In order to do so, change the Environment field to contain a PATH directive:

Wt 默认为静态编译,默认链接boost静态库。如果你希望选择动态编译,最简单的方式是定位依赖的dll,要改变环境变量 PATH:

PATH=c:/libraries/lib;c:/Boost/lib;<path to wt.dll>;<path to wthttp.dll>

Right-click on the example project you want to run and select 'Set as Startup Project'. Press F5 (Run). This will start a httpd server listening on all local interfaces, on port 8080, and you may browse the example at http://127.0.0.1:8080/hello

右键点击运行例子项目,选择“Set as Startup Project”,按F5运行。这会开启一个 httpd 服务器监听所有本地接口,端口位于8080,这时你可以通过  http://127.0.0.1:8080/hello  浏览例程

Examples that need extra files to run, should be executed from their source directory in order to find their dependency files (icons, css files, etc. Watch for 404 errors in Wt's output). To do so, set the 'Working directory' for the example to wt-2.x.x/examples/ExampleName. Some examples (e.g. the wt home page) need the 'resources' directory to work correctly. Copy the wt-2.x.x/resources to the example's source directory to solve this problem. Other examples (such as the Charts example) may require the installation of ExtJs. See the Wt reference manual for more information on how to obtain and install ExtJs.

例程执行时,会寻找所需要的文件,如 icons, css 等,如果找不到 Wt 会输出 404 错误。要观察错误,请设置 “Working directory” 为 wt-2.x.x/examples/ExampleName。有的例子,比如 wt 网站例子还需要设置 “resouces” 文件,可以通过拷贝 wt-2.x.x/resources 到例子文件夹即可解决。其他的例子,如 Charts ,需要安装 ExtJs。这个可以看 Wt 的手册以安装,比较简单。

These are all the command-line options that are available:

所有的 命令行 选项如下:

General options:
-h [ --help ] produce help message
-t [ --threads ] arg (=10) number of threads
--docroot arg document root for static files
--no-compression do not compress dynamic text/html and text/plain
responses
--deploy-path arg (=/) location for deployment

HTTP server options:
--http-address arg IPv4 (e.g. 0.0.0.0) or IPv6 Address (e.g. 0::0)
--http-port arg (=80) HTTP port (e.g. 80)

HTTPS server options:
--https-address arg IPv4 (e.g. 0.0.0.0) or IPv6 Address (e.g. 0::0)
--https-port arg (=443) HTTPS port (e.g. 443)
--ssl-certificate arg SSL server certificate chain file
e.g. "/etc/ssl/certs/vsign1.pem"
--ssl-private-key arg SSL server private key file
e.g. "/etc/ssl/private/company.pem"
--ssl-tmp-dh arg File for temporary Diffie-Hellman parameters
e.g. "/etc/ssl/dh512.pem"

Installing Wt¶〔安装 Wt〕

After compilation, right-click on 'INSTALL' and select 'build'. This will copy Wt header files an libraries to c:/Program Files/WT.

编译完后,右键点击 “INSTALL”并选择 “build”,将拷贝 Wt 头文件到 c:/Program Files/WT

Optional components¶〔可选组件〕

This involves installing SSL, zlib, and some other components. After installation as described here, rerun cmake so that it uses. These instructions are valid for Wt > 2.1.0.

可选组件可能包括 SSL,zlib及其他。安装后,重新运行 cmake以使用他们。

Preparations¶〔准备〕

In order to avoid to set paths to small library separately, we create a repository where we store them all. CMake will find this repository without intervention if you call it 'c:\libraries'.

为了避免给每个库单独设置路径,我们可以创建一个容器来存储他们,CMake会直接找到这个容器来定位他们,如 c:\libraries

mkdir c:\libraries
mkdir c:\libraries\lib
mkdir c:\libraries\include
创建文件夹(库和头文件〕

Download and build zlib¶〔下载并编译 zlib〕

Zlib is an optional dependency of Wt, which can be controlled by the CMake flag HTTP_WITH_ZLIB. With zlib, Wt compresses all http traffic by default, saving bandwidth.

  • Get zlib from http://www.zlib.net/ (direct link for version 1.2.3).
  • Open zlib-1.2.3\contrib\vstudio\vc8\zlibvc.sln
  • Select solution 'Debug', architecture 'Win32' (in the toolbar)
  • Right-click on project 'zlibstat', select Properties. In 'Configuration Properties'->'C/C++'->'Code Generation'->'Runtime Libraries' and set it to 'Multi-threaded Debug DLL (/MDd)'. Close the properties window.
  • Do the same with project 'zlibvc'
  • Right-click on project 'zlibstat', and select 'Build' to build it.
  • Select solution 'Release', architecture 'Win32'
  • Right-click on project 'zlibstat', select Properties. In 'Configuration Properties'->'C/C++'->'Code Generation'->'Runtime Libraries' and set it to 'Multi-threaded DLL (/MD)'. Close the properties window.
  • Do the same with project 'zlibvc'* Right-click on project 'zlibstat', and select 'Build' to build it.

Results are now located in the x86 directory. Copy them into our central repository location, renaming the debug library in the process:

cp contrib\vstudio\vc8\x86\ZlibStatDebug\zlibstat.lib c:\libraries\lib\zlibstatd.lib
cp contrib\vstudio\vc8\x86\ZlibStatRelease\zlibstat.lib c:\libraries\lib\

We also need zlib.h and zconf.h header files.

cp zlib.h zconf.h c:\libraries\include

OpenSSL

You need OpenSSL if you want to use Wt to support https mode. Grab a pre-compiled binary from http://www.openssl.org/related/binaries.html, install it in the default path (c:\OpenSSL) and Wt's CMake files will find and use OpenSSL (verify that HTTP_WITH_SSL is enabled).

Important Remarks

By default, Wt will build static libraries that are statically linked against boost. While this is convenient for quick deployment (the example binaries do not require dlls to run, so you do not have to set their PATHs correctly), many people prefer to use dll's, not in the least because your Wt applications will link much faster.

Two cmake options control how Wt is built, and what kind of boost libraries it uses:
  • BOOST_DYNAMIC: set to true to build against boost dlls. Set to false to link to static boost libraries.
  • SHARED_LIBS: set to true to build a Wt DLL, set to false to build a static Wt library.

When you double-checked the library directories but you still get build errors such as "cannot open file 'libboost_signals-vc90-mt-gd-1_35.lib'", you probably did not install or build the static boost files, while the BOOST_DYNAMIC option is set to false. Similarly, when the error indicates that boost_signals-vc90-mt-gd-1_35.lib is not found, you probably haven't installed or built the boost dlls, while BOOST_DYNAMIC is set to true.

Note that, when you build a static Wt library (SHARED_LIBS is false), you will get these boost-related linker errors only when you compile the examples.


类别: c++witty  查看评论
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!