The Joy of C++
Tuesday, April 22nd, 2008Recently Phusion announced the release of their apache integration for rails, modrails(passenger).
Having played around with the other rails deployment systems I was interested to see how this compared so I downloaded the gem to my OpenSolaris machine and was greeted with a great many build errors, it seems that even after all this time C++ still isn’t ready for prime time portability between platforms, let alone between compiler implementations.
I currently use Blastwave for most of my software as maintaining the scaffolding of my machine manually long ago became a chore. One of the quirks of this is that a majority of the software on my system is compiled via SunWorkshop (I’m currently using v 12) rather than the ubiquitous GCC which is really the only game in town for BSD/Linux systems. To complicate the issue Passenger uses C++ and Boost.
The Issues
The first problem came from the native ruby extension, they were accessing some Posix fields that aren’t normally included in the Solaris headers, some quick googling came up with the proper -D definitions of _XPG4_2 and __EXTENSIONS__ to solve this, these definitions were also required for later stages so I threw them in the root Rakefile provided by the build. (I still need to look into what environment variables I should have set to have mkmf generate a proper makefile on its own.)
After this the compile built the required Boost support libraries, Boost being what it is requires a very good implementation of the STL which basicly means you’re using STLPort, luckily Sun has realized this and there’s simply a compiler declaration of -library=stlport4 which needs to be added to all compile and link lines. The Rakefile also assumed you were building which g++ so I changed it to call CC (Sun Workshop’s c++ compiler) instead. There is also an issue with Boost assuming certain integer defines don’t exist on Solaris and redefining them but I’ll address that in the next section.
Finally onto the apache module itself, this was actually the most difficult section to get compiling because for testing purposes it contains sections that get compiled differently during the test build than during the deployable build. One of the major issues is that the ‘proper’ c++ headers cstdlib etc don’t always define all the ‘standard’ functions that stdlib.h do. Some examples are realpath, setenv, unsetenv etc. I tried to work around this various ways but I eventually just decided to revert all the headers to the classic version, which works it just polutes the main namespace which in this case isn’t really an issue since it seems that GCC does this anyways. As well there are various mutex references which conflict with the fact that /sys in Solaris contains mutex definitions so all those needed to be qualified as boost::mutex. Some functions from the standard library weren’t being dereferenced as std:: so I fixed those as well. After all this I ran into some interesting problems with the boost library cstdint which doesn’t properly realize that Solaris already defines the types it wants to define, so I just removed the inclusion of those headers for the Solaris build. After all this I got a successful build, and then I simply had to remove the -lstdc++ library from the link path as this is included automatically on Solaris and doesn’t exist as a library.
The test and benchmark code caused some minor problems as they assumed that stdlib was being brought in automatically (I think gcc does this to be helpful) so I needed to add that header for Solaris. As well I needed to add the standard solaris -lsocket and -lnsl declarations for the link stage.
The only problem remaining was their deployment script which assumes you need gcc etc, so after a little path hacking and some changes to stop it from trying to rebuild my jiggered build I got it successfully deployed.
My dirty tarball is located here for people who are interested in playing with it, but I certainly wouldn’t use it for a production site at this point without a lot more testing.
Posted in Software Development | Comments Off