Friday, March 21, 2014


Compiling Xalan, Xerces - C++ Source on multiple platforms

We spent hell a lot of time compiling C++ based source code of Xerces, Xalan XML libraries on Linux32, Linux64, OSX (x64), Windows x86, Windows x64 platforms.

This blog will list the steps needed to build these libraries for whatever use you have.
We did lots of painstaking research, patched the code manually and finally managed to build these libraries in multiple platforms.

We hope this could be useful for souls doing the same in the future.

The version of Xerces we needed was 2.8 (Xerces 2.8 - doesn’t add any new features compared to 2.7.0 but is rather focused on the bug fixes, optimizations, and build system improvements.  3.1 is available and the steps should be the same)

Xerces-C++ 2.8.0 comes with a wide range of precompiled libraries (total 23) for various CPU architectures, operation systems, and C++ compilers.  But we better compile the source code for your platform.

Xalan-C++ implements the XSL Transformations (XSLT) Version 1.0 and the XML Path Language (XPath) Version 1.0

You can download the source code of Xerces and Xalan from the following sites
http://xerces.apache.org/xerces-c/download.cgi
http://xalan.apache.org/old/xalan-c/download.html


Linux 32bit and 64bit

  • Set the variable to the path of the folder which contains the Xerces code
    export XERCESCROOT=<full-path-to-xerces-c-src_2_8_0>
    In our case
    export XERCESCROOT=/AC/WorkShop/SCAP/XalanXerces/Linux32/xerces-c-src_2_8_0
  • cd src/xercesc
  • Execute the script to generate the make files
    ./runConfigure -p linux -c gcc -x g++ -P /usr/local   (for 32 bit Linux)
    ./runConfigure -p linux -c gcc -x g++ -z -m64 -l -m64 -P /usr/local/   (for 64 bit Linux)
  • run the make script
    Make
  • We did not get any errors here, in case you run into errors, just double check the value of the variable 'XERCESCROOT'
  • Issue command sudo Make install  (this is important). This will copy the library files (.so) in /usr/local//lib
    When you issue this command, you might encounter an error
    xerces /obj: No such file or directorySome weird thing is, maybe sudo is unsetting the XERCESCROOT variable
    so do this
    sudo bash
    export XERCESCROOT ....
    make install
  • Check whether Xerces Library is really installed after the installation is completed. Go to the directory /usr/local/lib  and /usr/local/include to see whether there are files related to xerces.
Once this is done and the Xerces libraries are built, its time for Xalan!!!!
  • Set the variables 
  • Set the variable to the path where the Xerces binaries reside
    export XERCESCROOT=/usr/local
  • Set the path of the folder which contains the Xalan code to another variable
    export XALANCROOT=<full-path-to-xalan-c-src_1_0_0>
    In our case
    export XERCESCROOT=/AC/WorkShop/SCAP/XalanXerces/Linux32/xml-xalan/c
  • Execute the script to generate the make files
    ./runConfigure -p linux -c gcc -x g++ -P /usr/local   (for 32 bit Linux)
    ./runConfigure -p linux -c gcc -x g++ -z -m64 -l -m64 -P /usr/local/   (for 64 bit Linux)
  • run the make script
    Make
  • You might encounter into errors
    Cannot create 
    MsgCreator binaries - snippet of error below
    -L/home/training/Desktop/xerces-c-src_2_7_0/lib -lxerces-c ../../../../obj/MsgFileOutputStream.o ../../../../obj/ICUResHandler.o ../../../../obj/InMemHandler.o ../../../../obj/MsgCreator.o ../../../../obj/NLSHandler.o ../../../../obj/SAX2Handler.o -o ../../../../bin/MsgCreator ../../../../obj/InMemHandler.o: In functionInMemHandler::endElement(unsigned short const, unsigned short const, unsigned short const)':
    InMemHandler.cpp:(.text+0x502): undefined reference toxercesc_2_7::XMLString::compareString(unsigned short const*, unsigned short const*)' ../../../../obj/InMemHandler.o: In functionInMemHandler::startElement(unsigned short const
    , unsigned short const, unsigned short const, xercesc_2_7::Attributes const&)':
    For some reason there is a problem linking with xerces library
    the solution is to navigate the following directory
    cd src/xalanc/Utils/MsgCreator/

    And move the -lxerces-c command line param to the end, or just append another copy.
    So if this was the link command
    g++ -DLINUX -fPIC  -DXALAN_INMEM_MSG_LOADER   \
    -L/mnt/buildRoot/WorkShop/SCAP/XalanXerces/Linux32/xerces-c-src_2_8_0/lib -lxerces-c  ../../../../obj/MsgFileOutputStream.o ../../../../obj/ICUResHandler.o ../../../../obj/InMemHandler.o ../../../../obj/MsgCreator.o ../../../../obj/NLSHandler.o ../../../../obj/SAX2Handler.o -o ../../../../bin/MsgCreator

  • Just go to the above mentioned directory and issue this (-lxerces-c command line param goes to the end)
    g++ -DLINUX -fPIC  -DXALAN_INMEM_MSG_LOADER ../../../../obj/MsgFileOutputStream.o ../../../../obj/ICUResHandler.o ../../../../obj/InMemHandler.o ../../../../obj/MsgCreator.o ../../../../obj/NLSHandler.o ../../../../obj/SAX2Handler.o -o ../../../../bin/MsgCreator -L/mnt/buildRoot/WorkShop/SCAP/XalanXerces/Linux32/xerces-c-src_2_8_0/lib -lxerces-c 

  • Then we started getting the other errors regarding undeclared memmove(), strlen(), etc. All these errors seem to be bugs in Xalan 1.10's build files and source code.  So the solution is to
    just include #include <cstring> - 
    which will make those errors disappear
  • Once this is done you might get linker error
    /usr/bin/ld: cannot find -lxalanMsg
    The problem is the sym links are not created, but u can create them manually
    In the xml-xalan/c/lib folder u will find 3 files
    libxalanMsg.so.110.0
    libxalanMsg.so.110 (sym link)
    libxalanMsg.so (sym link)

    you make a copy of the libxalanMsg.so.110.0 and rename it as libxalanMsg.so
  • Run make again
  • Once this is done you might get linker error
    /usr/bin/ld: cannot find -lxalan-c
  • Again similarly, the problem is that the sym links are not created, but u can create them manually
    In the xml-xalan/c/lib folder u will find these files
    libxalan-c.so.110.0
    libxalan-c.so.110 (sym link)
    libxalan-c.so (sym link)

    you make a copy of the libxalan-c.so.110 and rename it as libxalan-c.so
  • Run make again
    And you will have all your libs !!
Congratulations!  Xerces and Xalan are built successfully for Linux64 and Linux32 platforms!

Mac OSX (x64)

  • The OSX source code of Xerces 2.8 has issues, especially if you are building x64 binaries or universal binaries for OSX.  The compilation will fail and the code will need to be manually patched.  Apparently this has been resolved in Xerces 3.x (we did not test)
  • Patch the Xerces code for the following files
    MacCarbonFile.cpp, MacOSPlatformUtils.cpp, MacOSUnicodeConverter.cpp, runConfigure (3 times), Makefile.incl

    The SVN diff file can be obtained here
    https://issues.apache.org/jira/secure/attachment/12372362/macsvn.diff
  • This manual patching is a painstaking process but it solves those pesky code issues.
  • Set the variable to the path of the folder which contains the Xerces code
    export XERCESCROOT=<full-path-to-xerces-c-src_2_8_0>
    In our case
    export XERCESCROOT=/AC/WorkShop/SCAP/XalanXerces/Macosx/xerces-c-src_2_8_0
  • cd src/xercesc
  • Execute the script to generate the make files
    ./runConfigure -p macosx -c gcc -x g++ -b 64 -z -m64 -l -m64 -l -arch -l x86_64 -z -arch -z x86_64  (for 64 bit MacOSX)
  • run the make script
    Make
  • We did not get any errors here, in case you run into errors, just double check the value of the variable 'XERCESCROOT'
  • Issue command sudo Make install  (this is important). This will copy the library files (.so) in /usr/local//lib
    When you issue this command, you might encounter an error
    xerces /obj: No such file or directorySome weird thing is, maybe sudo is unsetting the XERCESCROOT variable
    so do this
    sudo bash
    export XERCESCROOT ....
    make install
  • Check whether Xerces Library is really installed after the installation is completed. Go to the directory /usr/local/lib  and /usr/local/include to see whether there are files related to xerces.
  • Xalan is pretty straight forward in macosx
  • Set the variable to the path where the Xerces binaries reside
    export XERCESCROOT=/usr/local
  • Set the path of the folder which contains the Xalan code to another variable
    export XALANCROOT=<full-path-to-xalan-c-src_1_0_0>
    In our case
    export XERCESCROOT=/AC/WorkShop/SCAP/XalanXerces/Macosx/xml-xalan/c
  • Execute the script to generate the make files
    ./runConfigure -p macosx -c gcc -x g++ -b 64 -z -m64 -l -m64 -l -arch -l x86_64 -z -arch -z x86_64  (for 64 bit MacOSX)
  • run the make script
    Make
  • sudo Make install
    And Xalan installs like a breeze!!!   Atleast for us it did on macosx.  If you encounter errors, double check those pesky variables!
Congratulations!  Xerces and Xalan are built successfully on the MacOSX platform!


Windows
  • Open Visual studio and do hell!
  • blah ! blah!








From 
Kamlesh Mallick
Pune, India


Christophe Truc,
Nice, France


No comments:

Post a Comment