2013-11-05 24 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文檔的簡要介紹,說明生成的可執行文件在執行任何有趣的操作之前還需要一些選項。