This is almost identical to the way ns-2.34 is installed on Ubuntu 11.04, except for the lines in bold face:

Install the development files for X Windows plus the g++ compiler:
sudo apt-get install xorg-dev g++ xgraph

Fix the error in the linking of otcl by editing line 6304 of otcl-1.13/configure so that it reads
SHLIB_LD="gcc -shared"
instead of
SHLIB_LD="ld -shared"

Then, edit the file ns-2.34/tools/ and change the line 219 from
return GammaRandomVariable::GammaRandomVariable(1.0 + alpha_, beta_).value() * pow (u, 1.0 / alpha_);
return GammaRandomVariable(1.0 + alpha_, beta_).value() * pow (u, 1.0 / alpha_);

Next, change the lines 183 and 185 in file ns-2.34/mobile/ to read
resultPower = ErlangRandomVariable(Pr/m, int_m).value();
resultPower = GammaRandomVariable(m, Pr/m).value();

Add a line after line 64 in ns-2.34/mac/mac-802_11Ext.h to read:
#include <stddef.h>

Now the code will compile if you run ./install. However, you may not be able to run the ns executable. If you get an error stating that there has been a buffer overflow *** buffer overflow detected ***: ./ns terminated including a backtrace, you need to do the following to make it work:

Install gcc-4.4 and g++-4.4 including dependencies using the code below:
$ sudo apt-get install gcc-4.4 g++-4.4

Change the line 270 in tcl8.4.18/unix/ that reads
CC = @CC@
so it uses gcc version 4.4:
CC = gcc-4.4

Finally, run ./install from the ns-allinone-2.34 top folder again.

P.S. If you are moving and renaming ns-2 folders as time goes by, check the tip here on a potential problem with tk.