引出
最近在学习使用C++,另外对建站有点兴趣,所以就找到了WT。对于WT的详细介绍,这里不讲,直接看官网就好。
此文为本人原创,转载请注明出处。
先丢出官网上的干货:
- WT官方网站: https://www.webtoolkit.eu/wt/
- WT的下载页面: https://www.webtoolkit.eu/wt/download
安装
本文主要是讲Windows下如何安装配WT。
对于Windows,WT有一个已经都整理好的安装包,方便我们使用。
Windows WT (3.3.6)下载地址: https://github.com/kdeforche/wt/releases
注意:这里一定要选择清楚,自己的是什么版本的VS,还有应该选择什么版本的WT 是x86 or x64。
这里作者的电脑是VS2013,选择X64版本。下载好之后,打开,直接安装:
选好自己的安装路径:安装完之后,就算已经是安装好了WT了。然后就要进行配置
配置
首先打开VS,新建一个空的工程
然后右键工程属性,开始配置
开始配置:
以下引用配置原文:
```
To compile your own application using these binary releases, set the following properties in your MSVS project:
1. In C/C++ -> General, Additional Include Directories: c:/location/of/wt-x.y.z/
2. In C/C++ -> Preprocessor, ensure that WIN32 is defined. Also define HPDF_DLL, which will allow you to generate pdf
3. In Linker->General, Additional Library Directories: c:/location/of/wt-3.3.1/
4. Go to Linker->Input. In the Additional Dependencies, fill out the Wt libraries you want to link to. At the topleft of the dialog, check the active Configuration. If it's Debug, link to wtd.lib, wthttpd.lib (and optionally wtdbod.lib, wtdbobackendXXXd.lib, ...). If it's release, link to wt.lib, wthttp.lib (and optionally wtdbo.lib, wtdbobackendXXX.lib). Notice that the debug libraries have a 'd' suffix. Be carefull. You need different libraries depending on the Release/Debug configuration, since it's not possible to mix different versions of the MSVC runtime libraries in one
5. If you want to run your fresh application, set these
In the Debugging tab, set Command Arguments to --docroot . --http-address 0.0.0.0 --http-port
In the Debugging tab, set Environment to PATH=c:/location/of/wt-x.y.z/
Pasted from: http://redmine.emweb.be/projects/wt/wiki/Installing_Wt_on_MS_Windows#The-Easy-Method
```
1. 配置**附加包含目录**:
![](http://images2015.cnblogs.com/blog/861327/201608/861327-20160810204333152-1417611888.png)
配置为所安装的 `c:/location/of/wt-x.y.z/include`,即include文件夹
2. 配置**预编译器定义**
![](http://images2015.cnblogs.com/blog/861327/201608/861327-20160810204342059-1173411702.png)
配置内容为:
WIN32;
HPDF_DLL;
_SCL_SECURE_NO_WARNINGS;
这三个宏。
**注意**:最后一个宏,是为了编译的时候不出错,所以也要包含进去。
3. 配置**附加库目录**
![](http://images2015.cnblogs.com/blog/861327/201608/861327-20160810204350152-1441117930.png)
配置为:` c:/location/of/wt-3.3.1/lib`,也就是安装目录的lib文件夹。
4. 配置**附加依赖项**
![](http://images2015.cnblogs.com/blog/861327/201608/861327-20160810204357777-767568838.png)
配置为:添加所要用到的lib的名字。
- 通常,如果是DEBUG的话,就要增加wtd.lib, wthttpd.lib (and optionally wtdbod.lib, wtdbobackendXXXd.lib, ...).
- 如果是RELEASE的话,就要增加wt.lib, wthttp.lib (and optionally wtdbo.lib, wtdbobackendXXX.lib).
DEBUG和RELEASE的库的名字,就缺少一个d。
4. 最后,还要配置调试命令行。
![](http://images2015.cnblogs.com/blog/861327/201608/861327-20160810204405449-1790686948.png)
分别配置为--docroot . --http-address 0.0.0.0 --http-port 8080
PATH=c:/location/of/wt-x.y.z/bin
测试并运行
安装和配置好之后,终于可以测试一下了,下面我们选择了一个简单的小程序:
#include <Wt/WApplication>
#include <Wt/WBreak>
#include <Wt/WContainerWidget>
#include <Wt/WLineEdit>
#include <Wt/WPushButton>
#include <Wt/WText>
class HelloApplication : public Wt::WApplication
{
public:
HelloApplication(const Wt::WEnvironment& env);
private:
Wt::WLineEdit *nameEdit_;
Wt::WText *greeting_;
void greet();
};
HelloApplication::HelloApplication(const Wt::WEnvironment& env)
: Wt::WApplication(env)
{
setTitle("Hello world");
root()->addWidget(new Wt::WText("Your name, please ? "));
nameEdit_ = new Wt::WLineEdit(root());
Wt::WPushButton *button = new Wt::WPushButton("Greet me.", root());
root()->addWidget(new Wt::WBreak());
greeting_ = new Wt::WText(root());
button->clicked().connect(this, &HelloApplication::greet);
}
void HelloApplication::greet()
{
greeting_->setText("Hello there, " + nameEdit_->text());
}
Wt::WApplication *createApplication(const Wt::WEnvironment& env)
{
return new HelloApplication(env);
}
int main(int argc, char **argv)
{
return Wt::WRun(argc, argv, &createApplication);
}
将程序赋值进入工程,就可以编译运行了,其中可能会有很多警告。但是还是能够正常运行
- 运行界面
表示服务器已经运行
- 通过环回地址登陆
在浏览器中输入localhost:8080
然后登陆
可以看到程序所写的页面:
服务器后台方面也有反应:
![](http://images2015.cnblogs.com/blog/861327/201608/861327-20160810204429074-1364752338.png)
结语
好啦,这就完成了我们的WT+VS2013配置。