C++ and compatability



More content will be added to fill this space at some point in the future.

home :: writing :: cplusplusrant.txt

C++ and compatability

Tue Jan 14 2003

This morning (and most of yesterday), I have been fighting with C++. Trying to compile and link a program against xerces.

Due to my not following instructions correctly, and being given duff information, I was unable to compile it. This is fine I think, I will go and download the binary packages, these will have been compiled correctly.

I download the binary package, untar, and try to link against it. Loads and loads of errors. It turns out that GCC being shifted up a major version breaks binary compatability, so I cannot link against the library compiled with a different version. Hmm.

Next stop, the nightly builds of the development branch, there is going to be a release in a couple of weeks so it should be reasonably stable. Download this (it has been compiled with the same version of gcc), and untar. Now I get obsure syntax errrors when trying to compile my code. It turns out that now Xerces has been placed into a C++ namespace, and I need to prefix every reference to a xerces classname with "XERCES_CPP_NAMESPACE_QUALIFIER". For example:

   XERCES_CPP_NAMESPACE_QUALIFIER XMLString::copyString(fileName,systemID);

As you can see, this does wonders for code readability. I had to add these in about 50 places, and my code is only minimal. I would not have liked to convert a larger piece of code without automated tools.

This allows it to compile, which is a good start so I go and install the libraries and binaries on the server (running a slightly older version of the Operating System) and try it. It turns out that the machine with the new version of the compiler, also compiles against a more recent version of the standard C++ library, meaning that it doesn't run. At this point I could install the newer library, but that would end up with this machine having an aditional 20Mb library for compatability reasons and it isn't exactly ideal.

In the end, I just got better advice, and so was able to compile the new version on the server on which it was to be run. This was what I intended in the first place. Finally, you may have noticed that we had to change our code in order to use this new version. This code does not compile with previous versions of Xerces that do not define the namespace, leaving us with a problem, code that only works with the latest version. Luckily the preprocessor comes to my aid here, adding -DXERCES_CPP_NAMESPACE_QUALIFIER= to the compiler options effectively removes this.


This should not have been anywhere near as difficult as it was. Namespaces are possibly a good idea, but the should probably be implemented less like they were an afterthought. Also the binary format for libraries would be a lot nicer if it were a standard, as this would allow more sharing of libraries between software compiled with different compilers.

Last updated: 11:22, 23 Jul 2003 Link..