From campisano.org
Jump to navigation Jump to search


# cat /etc/debian_version 
# gcc -v
gcc version 4.4.5 (Debian 4.4.5-8) 
# uname -r


apt-get install libwt-dev libwtfcgi-dev libapache2-mod-fastcgi
a2enmod fastcgi

Apache config

from http://whocares.de/fastcgiexternalserver-demystified/all/1/

<IfModule mod_fastcgi.c>
    FastCGIExternalServer /tmp/my_app.fastcgi -host
    Alias /my_app /tmp/my_app.fastcgi

First Wt app

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

class HelloApplication : public Wt::WApplication
    HelloApplication(const Wt::WEnvironment& env);

    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);


g++ -lwtfcgi -lwt my_app.cpp -o myapp

Create config file

nano wt_config.xml

    <application-settings location="*">

Running spawned process

WT_CONFIG_XML=wt_config.xml spawn-fcgi -n -p 9000 ./myapp

See the result on http://localhost/my_app

Set-up an Eclipse CDT project =

Create an Eclipse project, maybe like there

Configure to Run and Debug

Run -> Debug Configurations
select 'C/C++ Application'
click on 'New launch configuration'
Name: "TestWt Spawned"
C/C++ Application: "/usr/bin/spawn-fcgi"
switch to tab 'Arguments'
Program arguments: "-n -p 9000 build/debug/TestWt"
Working directory: "${workspace_loc:TestWt/TestWt}"
switch to tab 'Environment'
click New...
Value: "wt_config.xml"
click Ok
switch to tab 'Debugger'
check 'Non-stop mode'
check 'Automatically debug forked processes'
click on Close

Now you can see the debug working, and run the page on http://localhost/my_app