个人工具

UbuntuHelp:BuildingWtFromSource

来自Ubuntu中文

跳转至: 导航, 搜索

Introduction

/!\ Note: This page is maintained by Tim Sutton (tim [at] linfiniti.com). /!\ /!\ /!\ This document is now only relevant for older versions of Witty and you can now easily install Wt from an Ubuntu PPA - please visit this page for instructions : http://www.webtoolkit.eu/wt/wiki/index.php/Installing_Wt_on_Ubuntu /!\ /!\ /!\ I am really eager to try out the Wt (a.k.a. 'witty') toolkit which allows you to deploy your C++ application as an ajax web app. They have recently published a nice article which provides an overview of the design thoughts behind Wt and some samples showing how it is used. I wanted to get it running on Ubuntu Dapper using apt for dependencies as much as possible. Here is what I did:

Getting Wt installed

Install Dependencies


sudo apt-get install libapache2-mod-fastcgi libfcgi-dev libboost-regex-dev libboost-regex1.33.1 libxml++2.6-dev libxml++2.6c2a libgd2-xpm libgd2-xpm-dev libboost-dbg libboost-date-time1.33.1 libboost-date-time-dev libmysql++-dev libmysql++2c2a cmake

Note: I assume you already have apache2 installed and running on your machine.

Source Download and Compilation Next I downloaded the Wt sources from anonymous CVS (I had some problems with the latest stable release and the developers suggested using CVS head instead).

cd ~/src/
cvs -d:pserver:[email protected]:/cvsroot/witty login
cvs -z3 -d:pserver:[email protected]:/cvsroot/witty co -P wt
cd wt
mkdir build
cd build
cmake -D DEPLOYROOT=/var/www/wt -D WEBUSER=www-data -D WEBGROUP=www-data ../

Which gave me an output looking like this:

-- Check for working C compiler: gcc
-- Check for working C compiler: gcc -- works
-- Check size of void*
-- Check size of void* - done
-- Check for working CXX compiler: c++
-- Check for working CXX compiler: c++ -- works
-- Looking for libxml++-2.6
-- Looking for libxml++-2.6 -- found
-- Configuring done
-- Generating done
-- Build files have been written to: /home/timlinux/dev/cpp/wt/build

At the time of writing ubuntu provides ccmake version 2.2-patch 3. This version has a known issue that needs to be compensated for by running the following command:

for i in `find . -name "build.make"`; do echo ".SUFFIXES:" >> $i; done

Now go on to make wt:

make && sudo make install

Preparing Apache

Now lets get the fastcgi module installed for apache:

sudo a2enmod

When prompted type

fastcgi

Now reload the apache modules:

sudo /etc/init.d/apache2 force-reload

Next create /etc/apache2/conf.d/witty with the following content:

#
# Added for wt web toolkit support
#

#first an additional handler for witty's fcg extension
<IfModule mod_fastcgi.c>
  AddHandler fastcgi-script .fcg
</IfModule>

#next make an alias for witty dir
Alias /wt /var/www/wt
<Directory /wt>
  Options -MultiViews +SymLinksIfOwnerMatch
  AllowOverride None
</Directory>

# finally treat all fcg of fgci files as fastcgi scripts
<Files ~ "\.(fcg|fcgi)$">
  Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
  AllowOverride None
</Files>

This creates an alias for the witty working directory and makes sure fastcgi will handle the .fcg extension properly. After these changes you need to restart apache:

sudo /etc/init.d/apache2 restart

Now make the witty web dir and give yourself permissions:

sudo mkdir -p /var/www/wt
sudo chown <yourusername> /var/www/wt

Now we link the libwt.so we built earlier, it should be in the ld search path. Edit (as sudo) /etc/ld.so.conf and check that you have /usr/local/lib in the list. If not, add it, and then run:

sudo ldconfig

Install the hello world example

First lets make all the examples

cd ~/dev/cpp/wt/build
make -C examples/

A simple example : hello world

cd ~/dev/cpp/wt/build/examples/hello

Now lets install the hello example. Now run the deploy script:

./deploy.sh

Now you can fire up your browser and point it to the example e.g.: http://localhost/wt/hello/hello.fcg BuildingWtFromSource?action=AttachFile&do=get&target=wt_helloworld.jpg

A more feature filled example : hangman

As before, just run the deploy scripts provided to install hangman:

cd ~/dev/cpp/wt/build/examples/hangman

Now run the deploy script:

./deploy.sh

Before the hangman example can be used, you need to create a database and point to that (I assume you already have mysql set up and running locally on your system):

cd ~/dev/cpp/wt/examples/hangman
mysql -u<your mysql user name> -p < dbscript

Enter your password when prompted. Also you need to make a tiny config file for Wt to be able to connect to the database properly:

echo "<your mysql user name>" > /var/www/wt/hangman/HangmanDb.info
echo "<your mysql password>" > /var/www/wt/hangman/HangmanDb.info

Obviously you should replace items between < > brackets in the above instructions with their real values. Now you can fire up your browser and point it to the example e.g.: http://localhost/wt/hangman/hangman.fcg BuildingWtFromSource?action=AttachFile&do=get&target=wt_hangman.jpg

FAQ

Question: When running make I get a bunch of 'WWebWidget: No such file of directory' type errors like this:

Scanning dependencies of target xl
Building CXX object xlobject/src/CMakeFiles/xl.dir/baseobject.o
Linking CXX static library libxl.a
Scanning dependencies of target wt
In file included from ../src/wt/WInteractWidget.C:6:
../src/wt/WInteractWidget:10:22: error: WWebWidget: No such file or directory
../src/wt/WInteractWidget:18: error: expected class-name before ‘{’ token
../src/wt/WInteractWidget:22: error: expected `)' before ‘*’ token
../src/wt/WInteractWidget:27: error: expected `:' before ‘signals’
../src/wt/WInteractWidget:37: error: ‘Wt’ has not been declared
../src/wt/WInteractWidget:37: error: ‘Signal’ was not declared in this scope
../src/wt/WInteractWidget:37: error: expected primary-expression before ‘int’
../src/wt/WInteractWidget:37: error: ISO C++ forbids declaration of ‘signals’ with no type
../src/wt/WInteractWidget:37: error: expected ‘;’ before ‘int’
../src/wt/WInteractWidget:46: error: ‘Wt’ has not been declared
../src/wt/WInteractWidget:46: error: ISO C++ forbids declaration of ‘Signal’ with no type
../src/wt/WInteractWidget:46: error: expected ‘;’ before ‘<’ token
../src/wt/WInteractWidget:55: error: ‘Wt’ has not been declared
../src/wt/WInteractWidget:55: error: ISO C++ forbids declaration of ‘Signal’ with no type
../src/wt/WInteractWidget:55: error: expected ‘;’ before ‘<’ token
../src/wt/WInteractWidget:62: error: ‘Wt’ has not been declared
../src/wt/WInteractWidget:62: error: ISO C++ forbids declaration of ‘Signal’ with no type
../src/wt/WInteractWidget:62: error: expected ‘;’ before ‘<’ token
../src/wt/WInteractWidget:67: error: ‘Wt’ has not been declared
../src/wt/WInteractWidget:67: error: ISO C++ forbids declaration of ‘Signal’ with no type
../src/wt/WInteractWidget:67: error: expected ‘;’ before ‘<’ token
../src/wt/WInteractWidget:72: error: ‘Wt’ has not been declared
../src/wt/WInteractWidget:72: error: ISO C++ forbids declaration of ‘Signal’ with no type
../src/wt/WInteractWidget:72: error: expected ‘;’ before ‘<’ token
../src/wt/WInteractWidget:77: error: ‘Wt’ has not been declared
../src/wt/WInteractWidget:77: error: ISO C++ forbids declaration of ‘Signal’ with no type
../src/wt/WInteractWidget:77: error: expected ‘;’ before ‘<’ token
../src/wt/WInteractWidget:81: error: ‘Wt’ has not been declared
../src/wt/WInteractWidget:81: error: ISO C++ forbids declaration of ‘Signal’ with no type
../src/wt/WInteractWidget:81: error: expected ‘;’ before ‘<’ token
../src/wt/WInteractWidget:85: error: ‘Wt’ has not been declared
../src/wt/WInteractWidget:85: error: ISO C++ forbids declaration of ‘Signal’ with no type
../src/wt/WInteractWidget:85: error: expected ‘;’ before ‘<’ token
../src/wt/WInteractWidget:89: error: ‘Wt’ has not been declared
../src/wt/WInteractWidget:89: error: ISO C++ forbids declaration of ‘Signal’ with no type
../src/wt/WInteractWidget:89: error: expected ‘;’ before ‘<’ token
../src/wt/WInteractWidget:92: error: ‘Wt’ has not been declared
../src/wt/WInteractWidget:92: error: ISO C++ forbids declaration of ‘Signal’ with no type
../src/wt/WInteractWidget:92: error: expected ‘;’ before ‘<’ token
../src/wt/WInteractWidget:94: error: expected `:' before ‘slots’
../src/wt/WInteractWidget:95: error: expected primary-expression before ‘void’
../src/wt/WInteractWidget:95: error: ISO C++ forbids declaration of ‘slots’ with no type
../src/wt/WInteractWidget:95: error: expected ‘;’ before ‘void’
../src/wt/WInteractWidget:101: error: ‘DomElement’ has not been declared
../src/wt/WInteractWidget.C:8: error: expected `)' before ‘*’ token
../src/wt/WInteractWidget.C:45: error: variable or field ‘updateDom’ declared void
../src/wt/WInteractWidget.C:45: error: ‘int WInteractWidget::updateDom’ is not a static member of ‘class WInteractWidget’
../src/wt/WInteractWidget.C:45: error: ‘DomElement’ was not declared in this scope
../src/wt/WInteractWidget.C:45: error: ‘element’ was not declared in this scope
../src/wt/WInteractWidget.C:45: error: expected primary-expression before ‘bool’
../src/wt/WInteractWidget.C:45: error: initializer expression list treated as compound expression
../src/wt/WInteractWidget.C:46: error: expected ‘,’ or ‘;’ before ‘{’ token
../src/wt/WInteractWidget.C:69: error: no ‘void WInteractWidget::gotClick()’ member function declared in class ‘WInteractWidget’
../src/wt/WInteractWidget.C: In member function ‘void WInteractWidget::gotClick()’:
../src/wt/WInteractWidget.C:71: error: ‘clickData’ was not declared in this scope
../src/wt/WInteractWidget.C:71: error: ‘emit’ was not declared in this scope
make[2]: *** [../src/wt/WInteractWidget] Error 1
make[1]: *** [src/CMakeFiles/wt.dir/all] Error 2
make: *** [all] Error 2

Answer: This is a known issue with the version of ccmake (v 2.2 patch 3) shipped with Ubuntu Dapper. Make sure you do the

for i in `find . -name "build.make"`; do echo ".SUFFIXES:" >> $i; done

step described in the 'source download and compilation' section above.

Question: Its all built and installed, but when I try to run an example, I get a heap of errors in my apache error logs like this:

[Tue Jul 18 15:57:08 2006] [notice] FastCGI: process manager initialized (pid 14761)
[Tue Jul 18 15:57:08 2006] [notice] Apache/2.0.55 (Ubuntu) mod_fastcgi/2.4.2 PHP/4.4.2-1build1 configured -- resuming normal operations
[Tue Jul 18 15:57:09 2006] [warn] FastCGI: (dynamic) server "/var/www/wt/hangman/hangman.fcg" started (pid 14767)
Creating new session: DyOaSyj6eb5T5nVN
Spawned new application: pid=14769
bind: No such file or directory
SIGCHLD received
Child pid is 14769
Deleting session: DyOaSyj6eb5T5nVN
[Tue Jul 18 15:57:13 2006] [warn] FastCGI: (dynamic) server "/var/www/wt/hangman/hangman.fcg" started (pid 14770)
[Tue Jul 18 15:57:16 2006] [warn] FastCGI: (dynamic) server "/var/www/wt/hangman/hangman.fcg" started (pid 14771)
[Tue Jul 18 15:57:19 2006] [warn] FastCGI: (dynamic) server "/var/www/wt/hangman/hangman.fcg" started (pid 14772)
connect: No such file or directory
Giving up on session: DyOaSyj6eb5T5nVN
Creating new session: lSwANRPjGVEqcVCu
Spawned new application: pid=14773
bind: No such file or directory
SIGCHLD received
Child pid is 14773
Deleting session: lSwANRPjGVEqcVCu
[Tue Jul 18 15:57:22 2006] [warn] FastCGI: (dynamic) server "/var/www/wt/hangman/hangman.fcg" started (pid 14774)
[Tue Jul 18 15:57:25 2006] [warn] FastCGI: (dynamic) server "/var/www/wt/hangman/hangman.fcg" started (pid 14775)
[Tue Jul 18 15:57:28 2006] [warn] FastCGI: (dynamic) server "/var/www/wt/hangman/hangman.fcg" started (pid 14776)
connect: No such file or directory
Giving up on session: lSwANRPjGVEqcVCu
Creating new session: FAScLywZHXv9eIIa
Spawned new application: pid=14777
bind: No such file or directory
SIGCHLD received
Child pid is 14777
Deleting session: FAScLywZHXv9eIIa
[Tue Jul 18 15:57:31 2006] [warn] FastCGI: (dynamic) server "/var/www/wt/hangman/hangman.fcg" started (pid 14778)
[Tue Jul 18 15:57:34 2006] [warn] FastCGI: (dynamic) server "/var/www/wt/hangman/hangman.fcg" started (pid 14779)
[Tue Jul 18 15:57:37 2006] [warn] FastCGI: scheduled the start of the last (dynamic) server "/var/www/wt/hangman/hangman.fcg" process: reached dynamicMaxClassProcs (10)
[Tue Jul 18 15:57:37 2006] [warn] FastCGI: (dynamic) server "/var/www/wt/hangman/hangman.fcg" started (pid 14780)
connect: No such file or directory
Giving up on session: FAScLywZHXv9eIIa
Creating new session: yfW8iOFppMTodz92
Spawned new application: pid=14781
bind: No such file or directory
SIGCHLD received
Child pid is 14781
Deleting session: yfW8iOFppMTodz92
[Tue Jul 18 15:57:43 2006] [error] [client 127.0.0.1] FastCGI: comm with (dynamic) server "/var/www/wt/hangman/hangman.fcg" aborted: (first read) idle timeout (30 sec)
[Tue Jul 18 15:57:43 2006] [error] [client 127.0.0.1] FastCGI: incomplete headers (0 bytes) received from server "/var/www/wt/hangman/hangman.fcg"
connect: No such file or directory
Giving up on session: yfW8iOFppMTodz92
Creating new session: veXzGFFpqTIr0W65
Spawned new application: pid=14782
bind: No such file or directory
SIGCHLD received
Child pid is 14782
Deleting session: veXzGFFpqTIr0W65
connect: No such file or directory
Giving up on session: veXzGFFpqTIr0W65
Creating new session: ZWDDcvLjlI23NcFo
Spawned new application: pid=14783
bind: No such file or directory
SIGCHLD received
.
.
.
etc

Answer: This is probably because the witty run dir is not created and or writeable by the www-data user. Make sure your /usr/run/wt dir is present with the correct permissions.

Question: When I try to run the hangman example, I get 'failed to remain running' messages like this:

[Wed Jul 19 13:56:55 2006] [warn] FastCGI: (dynamic) server "/var/www/wt/hangman/hangman.fcg" has failed to remain running for 30 seconds given 3 attempts, its restart interval has been backed off to 600 seconds

Answer: To be answered

Question: When I try to run the hangman example I get 'Exec format error' messages like this:

[Wed Jul 19 10:07:41 2006] [error] [client 127.0.0.1] (8)Exec format
error: exec of '/var/www/wt/hangman/icons/hangman1.png' failed,
referer: http://localhost/wt/hangman/hangman.fcg?wtd=Vry2TLKMnkAutkeX&js=yes&ajax=yes

Answer: This is because your apache configuration is trying to treat png images as script files. Are you sure you entered the /etc/apache2/conf.d/witty settings exactly as shown in the instructions above?