2013-11-05 26 views
0

我正尝试在WT中开始开发,但它不能正常工作。我使用Windows 8,下载了Wt 3.3.1,并下载了具有GCC编译器和GDB调试器的codeblocks-12.11mingw-setup_user.exe。但是我没有使用代码块,因为编译器不喜欢WtConfig.h中的cmake preproccessor指令。所以我尝试手动编译(我是使用这种技术的新手,所以我不得不查找它)。Wt a.exe文件将不会运行

我有我的项目为:

└───HelloWorldWt 
    └───source 
     ├───bin 
     │ ├───Debug 
     │ │ └───CMakeFiles 
     │ │  └───CMakeFiles 
     │ └───Release 
     ├───build 
     └───source 
     | └───CMakeFiles 
     |  └───wt_project.wt.dir 
     |  |___CMakeLists.txt 
     |  | 
     |  |___main.cpp 
     |____CMakeLists.txt 

的main.cpp中有(这是http://www.webtoolkit.eu/wt/examples/的HelloWorld示例):

/* * 版权所有(C)2008 Emweb BVBA,Heverlee的,比利时。 * *有关使用条款,请参阅许可证文件。 */

#include <Wt/WApplication> 
#include <Wt/WBreak> 
#include <Wt/WContainerWidget> 
#include <Wt/WLineEdit> 
#include <Wt/WPushButton> 
#include <Wt/WText> 

// c++0x only, for std::bind 
// #include <functional> 

using namespace Wt; 

/* 
* A simple hello world application class which demonstrates how to react 
* to events, read input, and give feed-back. 
*/ 
class HelloApplication : public WApplication 
{ 
public: 
    HelloApplication(const WEnvironment& env); 

private: 
    WLineEdit *nameEdit_; 
    WText *greeting_; 

    void greet(); 
}; 

/* 
* The env argument contains information about the new session, and 
* the initial request. It must be passed to the WApplication 
* constructor so it is typically also an argument for your custom 
* application constructor. 
*/ 
HelloApplication::HelloApplication(const WEnvironment& env) 
    : WApplication(env) 
{ 
    setTitle("Hello world");        // application title 

    root()->addWidget(new WText("Your name, please ? ")); // show some text 
    nameEdit_ = new WLineEdit(root());      // allow text input 
    nameEdit_->setFocus();         // give focus 

    WPushButton *button 
    = new WPushButton("Greet me.", root());    // create a button 
    button->setMargin(5, Left);       // add 5 pixels margin 

    root()->addWidget(new WBreak());      // insert a line break 

    greeting_ = new WText(root());       // empty text 

    /* 
    * Connect signals with slots 
    * 
    * - simple Wt-way 
    */ 
    button->clicked().connect(this, &HelloApplication::greet); 

    /* 
    * - using an arbitrary function object (binding values with boost::bind()) 
    */ 
    nameEdit_->enterPressed().connect 
    (boost::bind(&HelloApplication::greet, this)); 

    /* 
    * - using a c++0x lambda: 
    */ 
    // b->clicked().connect(std::bind([=]() { 
    //  greeting_->setText("Hello there, " + nameEdit_->text()); 
    // })); 
} 

void HelloApplication::greet() 
{ 
    /* 
    * Update the text, using text input into the nameEdit_ field. 
    */ 
    greeting_->setText("Hello there, " + nameEdit_->text()); 
} 

WApplication *createApplication(const WEnvironment& env) 
{ 
    /* 
    * You could read information from the environment to decide whether 
    * the user has permission to start a new application 
    */ 
    return new HelloApplication(env); 
} 

int main(int argc, char **argv) 
{ 
    /* 
    * Your main method may set up some shared resources, but should then 
    * start the server application (FastCGI or httpd) that starts listening 
    * for requests, and handles all of the application life cycles. 
    * 
    * The last argument to WRun specifies the function that will instantiate 
    * new application objects. That function is executed when a new user surfs 
    * to the Wt application, and after the library has negotiated browser 
    * support. The function should return a newly instantiated application 
    * object. 
    */ 
    int retval = WRun(argc, argv, &createApplication); 
    char* ch = new ch(); 
    cin() >> ch; 
    return retval; 
} 

的HelloWorldWt /的CMakeLists.txt有:

CMAKE_MINIMUM_REQUIRED(VERSION 2.6) 

PROJECT(WT_HELLO_WORLD) 

SET (WT_CONNECTOR "wtfcgi" CACHE STRING "Connector used (wthttp or wtfcgi)") 

ADD_SUBDIRECTORY(source) 

的HelloWorldWt /源/的CMakeLists.txt有

SET(WT_PROJECT_SOURCE 
main.cpp 
) 

SET(WT_PROJECT_TARGET wt_project.wt) 

ADD_EXECUTABLE(${WT_PROJECT_TARGET} ${WT_PROJECT_SOURCE}) 

TARGET_LINK_LIBRARIES(${WT_PROJECT_TARGET} ${WT_CONNECTOR} wt) 

INCLUDE_DIRECTORIES("C:/Users/Me/My Code Libraries/wt-3.3.1/src") 

我然后跑

cmake .. -G "MinGW Makefiles" from the MyCode directory 

创建了一个几个文件, 这创建了cmake_install.cmake等文件。

然后我跑:cmake的.. -G “MinGW的Makefile文件” 从HelloWorldWt /源 然后我跑:cmake的-P cmake_install.cmake

然后我有: 我的代码\ HelloWorldWt \源\编译\ CMakeFiles \ 2.8.12 \ CompilerIdCXX \ a.exe文件,然后单击该程序运行它,并打开一个控制台窗口,然后关闭。

我缺少什么?在这里我想获得一个重量应用程序运行,但似乎无法做到这一点还没有

(也许我应该注意的是,当我使用命令:

cmake -P cmake_install.cmake 

的CMD控制台,回复与

-- Install configuration: "" 

,然后又回到了提示 - 如果这能帮助)。

+0

不要从资源管理器中单击它。运行cmd(通过右键单击CompilerIdCXX并在此处选择“打开命令”窗口),然后从命令行执行它 - 这会向您显示正在打印的错误,因为窗口不会以这种方式关闭。 –

+0

当我从该文件夹运行a.exe时,控制台不会打印任何消息并立即结束,无所事事。 – user904542

+0

PATH中是否都需要库? – UldisK

回答

-2

我们使用g ++,因为它的C++接口(与gcc相反)和scons作为构建模型。这工作得很好,而且部署起来非常简单。我会建议尝试下一个Ubuntu 14.04发行版,因为它的软件包中将包含一个稳定的Wt版本。

+0

这看起来不相关,-1。 CMake非常清楚使用适当的C++编译器驱动程序来处理扩展名为“.cpp”的任何内容,并且在Ubuntu上尝试不会解决Windows上的任何问题(GNU/Linux可能比Windows更适合开发,但这不会使其与特定于Windows的问题)。 –

0
My Code\HelloWorldWt\source\build\CMakeFiles\2.8.12\CompilerIdCXX\a.exe 

不是你想运行文件。这是一个内部CMake测试,cmake在配置期间创建,以验证所选编译器甚至编译和检测目标体系结构。

您可执行将被称为

My Code\HelloWorldWt\source\build\wt_project.wt.exe 

当你真正编译

要编译它,你要么打电话make,或其他适当的build命令取决于所选择的发电机,或者你可以问cmake用命令来调用它给你:

cmake --build . 

您粘贴的代码包含语法错误—

cin() >> ch; 

应该

std::cin >> ch; 

(和ch应该是char,而不是char *)—确认您尚未尝试编译它。

我应该补充一下WT文档的简要介绍,说明生成的可执行文件在执行任何有趣的操作之前还需要一些选项。