Tuesday, 13 December 2011

Compile dosxyz_show on Ubuntu (10.04, 14.04)

I was surprised to find that this program does't come compiled with BEAM (or other EGSnrc packages) nor does it come packaged using the autotools suite.  Well, we can easily make up for this by compiling it the old fashioned way.  Sadly, whatever functionality autotools would normally provide, we must now provide ourselves.  So get ready and relax, this won't be too painful.

Before this will work, you must have installed EGSnrc (this is where the source for dosxyz_show is found).  Go to the source for dosxyz_show, found in
cd $HEN_HOUSE/omega/progs/dosxyz_show/
The only files present here are the Makefile (which holds the details needed by the compiler) and the .c file (which holds the code to be compiled).  Like every good linux user, I tried running this on the command line as soon as I saw the Makefile:
make
If everything were fine, this should work and then you are done installing dosxyz_show.  Unfortunately for me, the following error chain was produced (I removed many lines from this output because it was too long!):
gcc -O2  -I/usr/X11R6/include  -o /home/xxxxxx/HEN_HOUSE/bin/i686-pc-linux-gnu-/dosxyz_show -L/usr/X11R6/lib  dosxyz_show.c -lXm -lXt -lX11 -lmdosxyz_show.c:46:22: error: Xm/XmAll.h: No such file or directorydosxyz_show.c:101: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘NoName_status’dosxyz_show.c:109: error...
Looking at the first error:
Xm/XmAll.h: No such file or directory
It is clear that a library is missing.  So I went to the NRC site for dosxyz_show and found that I needed to add the Motif libraries.  The documentation recommended installing LessTif, an open-source equivalent.  In fact, it is not equivalent (which can be validated by looking through the files in the package... some includes we will need are missing at least).  A google search for the file name revealed a file listing for the package libmotif-dev.  So we install that, naively assuming that it's the correct package:
sudo apt-get install libmotif-dev
I also noticed that the default paths in the Makefile were not appropriate for Ubuntu.  In particular, we see this in the Makefile:
X11_include = -I/usr/X11R6/include
# On our system, Motif include files are in /usr/X11R6/include/Xm =>
# we don't need a separate -I for Motif. If this is different on your
# system, adjust accordingly.
Motif_include =
X11_libdir = -L/usr/X11R6/lib
# On our system, the Motif library is /usr/X11R6/lib =>
# we don't need a separate -L for Motif. If this is different on your
# system, adjust accordingly.
Motif_libdir =
Searching for the directories listed above reveals that they do not exist.  OK, lets set the paths correctly. Use these settings instead:
X11_include = -I/usr/include/X11
# On our system, Motif include files are in /usr/X11R6/include/Xm =>
# we don't need a separate -I for Motif. If this is different on your
# system, adjust accordingly.
Motif_include =
X11_libdir = -L/usr/lib/X11
# On our system, the Motif library is /usr/X11R6/lib =>
# we don't need a separate -L for Motif. If this is different on your
# system, adjust accordingly.
Motif_libdir =
Now we compile again
make
If you're using Ubuntu 14.04, that may have been sufficient. However, I sometimes get the following error:

In file included from /usr/include/Xm/XmAll.h:33:0,
                 from dosxyz_show.c:34:
/usr/include/Xm/Xm.h:59:27: fatal error: X11/Intrinsic.h: No such file or directory
 #include <X11/Intrinsic.h>

Which can be solved by installing libxt-dev:

sudo apt-get install libxt-dev
make 

If you've added the environment variables suggested during the EGS install, the path to the executable should already be in your path (check this by trying to auto-complete dosxyz_show on the shell).

If you're using Ubuntu 10.04, you should end up with a new error!  Progress!
gcc -O2  -I/usr/X11R6/include  -o /home/xxxxxxx/HEN_HOUSE/bin/i686-pc-linux-gnu-/dosxyz_show -L/usr/X11R6/lib  dosxyz_show.c -lXm -lXt -lX11 -lmIn file included from /usr/include/Xm/XmAll.h:46,                 from dosxyz_show.c:46:/usr/include/Xm/Xm.h:59:34: error: X11/extensions/Print.h: No such file or directoryIn file included from /usr/include/Xm/XmAll.h:46,                 from dosxyz_show.c:46:/usr/include/Xm/Xm.h:827: error: expected specifier-qualifier-list before ‘XPContext’In file included from /usr/include/Xm/XmAll.h:86,                 from dosxyz_show.c:46:/usr/include/Xm/Print.h:46...
Identifying the first error:
X11/extensions/Print.h: No such file or directory
it is clear that my package installation didn't fully do the trick.  Another google search for the error revealed that I can search for the packages containing a certain file using apt-file.  So we set that up and look for our file (it may take a minute or so to update the apt-file index):
sudo apt-get install apt-file
sudo apt-file update
apt-file search X11/extensions/Print.h
x11proto-print-dev: usr/include/X11/extensions/Print.h
The search reveals that the file is in the x11proto-print-dev package.  We install it:
sudo apt-get install x11proto-print-dev
and we try to build again, with complete success (nevermind all the warnings about fscanf):
gcc -O2  -I/usr/include/X11  -o /home/xbaker/staging/beamnrc/HEN_HOUSE/bin/i686-pc-linux-gnu-/dosxyz_show -L/usr/lib/X11  dosxyz_show.c -lXm -lXt -lX11 -lmdosxyz_show.c: In function ‘get_data’:dosxyz_show.c:1280: warning: ignoring return value of ‘fscanf’, declared with attribute warn_unused_result...
The binary executable produced by the compilation process must be made executable, and then you can run it:
cd $HEN_HOUSE/omega/progs/dosxyz_show 
chmod u+x dosxyz_show
./dosxyz_show <EGSPHANT> <3DDOSE>
Done!

Wednesday, 7 December 2011

Ensuring vmc++ has the standard library

The short answer:

If you're getting an error like this:
./vmcpp: error while loading shared libraries: libstdc++.so.5: cannot open shared object file: No such file or directory
while running VMC++, then you need to add gcc-3.3 to your system, which adds the missing library file mentioned in the error.  In Ubuntu, you can fix this by adding this line to your /etc/apt/sources.list file (choose your mirror from http://packages.ubuntu.com/hardy/i386/libstdc++5/download):

deb http://ubuntu.wikimedia.org/ubuntu/ hardy main universe

and then opening synaptic, reloading, and installing the libstdc++5 package:
sudo apt-get install libstdc++5


More details

In my version of Ubuntu (10.04 lucid), the standard c++ library is the one that comes packaged with gcc-4.4. Unfortunately, the version of the VMC++ monte carlo package that I have was compiled with an older version of gcc. Here is the message I received:
 ./vmcpp: error while loading shared libraries: libvmcpp.so: cannot open shared object file: No such file or directory 
Ooops, that's actually the first error I received while running the program. That simply requires the addition of the lib files that came with the VMC++ executable (including libphsp_source.so, libsimple_source.so, libvmcpp.so) to your system's library path.  If you don't want to install them the 'correct' way, you can get away with adding their directory to the environment variable LD_LIBRARY_PATH, like this (in bash):
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:`pwd` 
Indeed, the real error I received was this:
./vmcpp: error while loading shared libraries: libstdc++.so.5: cannot open shared object file: No such file or directory
This required some digging.  A Google search revealed the Ubuntu repositories containing my desired package (libstdc++5).  After choosing the package (the one with /usr/lib/libstdc++.so.5 for my system) and -- on the next page -- my architecture (i386), I was guided to the download location.  I added the appropriate line to my /etc/apt/sources.list file, reloaded my synaptic, then installed the package libstdc++5.