First, do the same things as you would do for the ns-2.34 and Ubuntu 10.10 installation, i.e.:

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/ranvar.cc and change the line 219 from
return GammaRandomVariable::GammaRandomVariable(1.0 + alpha_, beta_).value() * pow (u, 1.0 / alpha_);
to
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/nakagami.cc to read
resultPower = ErlangRandomVariable(Pr/m, int_m).value();
and
resultPower = GammaRandomVariable(m, Pr/m).value();

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/Makefile.in that reads
CC = @CC@
so it appends the version parameter for version 4.4:
CC = @CC@ -V 4.4
Make sure it is a capital V.

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

See also: Installing ns-2.34 on Ubuntu 11.10 Oneiric Ocelot