Sunday, April 8, 2012

Installing and running xerces in c/c++

I am working on storing data in XML files.I faced a lot of problems while installing the xerces from its binary distribution.I hav'nt found any good tutorial on the internet for its installation and running.
Therefore  I am posting here steps that I followed in order to install /run it.

1.Download the binary distribution of xerces according to your system configuration from the
http://xerces.apache.org

if you are on 32 bit system you can download this.
http://apache.mirrors.redwire.net//xerces/c/3/binaries/xerces-c-3.1.1-x86-linux-gcc-3.4.tar.gz

2.Extract the .tar.gz
     -> using command line or you can directly open it with archive manager.
 extracting the file will create a sub-directory "xerces-c-3.1.1-x86-linux-gcc-3.4"

lets say i have extracted in my /home/aditya/tools/ directory.
so its full path will be
/home/aditya/tools/xerces-c-3.1.1-x86-linux-gcc

3.Now open your .bashrc file which is in your home directory i.e /home/aditya/.bashrc

add following line in it (modify your path according to the location of extracted files)


export PATH="$PATH:/home/aditya/tools/xerces-c-3.1.1-x86-linux-gcc-3.4/bin"

export LD_LIBRARY_PATH=/home/aditya/tools/xerces-c-3.1.1-x86-linux-gcc-3.4/lib:$LD_LIBRARY_PATH



export PKG_CONFIG_PATH=/usr/lib/pkgconfig:/usr/local/lib/pkgconfig:/home/aditya/tools/xerces-c-3.1.1-x86-linux-gcc-3.4/lib/pkgconfig

4.lets say my program name is xml.main.cpp
then run it with g++ like this

g++ -I/home/aditya/tools/xerces-c-3.1.1-x86-linux-gcc-3.4/include/ -L /home/aditya/tools/xerces-c-3.1.1-x86-linux-gcc-3.4/lib/ -lxerces-c -g -Wall -pedantic  xml.main.cpp

5.Its tedious to write these things in each compilation.So you can add an alias in you .bashrc file

alias gxr="g++ -I/home/aditya/tools/xerces-c-3.1.1-x86-linux-gcc-3.4/include/ -L /home/aditya/tools/xerces-c-3.1.1-x86-linux-gcc-3.4/lib/ -lxerces-c -g -Wall -pedantic"

now you can compile like

gxr xml.main.cpp


If you found any problem in above steps..you can ask in comments.!!

Enjoy