views:

161

answers:

2

I want to build my program with LSB C++ Compiler from the Linux Standard Base http://www.linuxfoundation.org/collaborate/workgroups/lsb. Program depends on the Boost library, built with gcc 4.4 version. Compilation fails. Is it possible to build the Boost library with LSB C++ Compiler? Alternatively, is it possible to build the Boost library with some old gcc version, what version is recommended? My final goal is to get my executable and third-party Boost libraries running on most Linux distributions.

Generally, what can be done to get better binary compatibility for Linux distributions, developing C++ closed-source application depending on the Boost library?

+2  A: 

LSB C++ compiler is not actually a compiler. The lsbc++ executable is a wrapper around GCC compiler that is installed on your system (the actual compiler can be controlled via --lsb-cxx option). You will most likely hack into boost build system for it to call LSB wrapper instead of native gcc compiler.

So the issues that may arise are most likely not that LSB compiler can't compile the language constructs, but instead, that there are some linking issues.

For example, LSB compiler by default discards any shared libraries the code is linked against, unless they belong to LSB. This may lead to linking errors if BOOST relies on such libraries. This can be controlled via LSBCC_SHAREDLIBS environment variable, but you should make sure you ship these libs along with your product.

Another issue is that LSB falls behind GCC compiler releases (and BOOST may crawl into all dark corners of compilers). As far as I know, GCC 4.4 is not tested sufficiently, so you'd better try it with 4.3 compiler.

And Google doesn't seem to find anything related to building boost with LSBCC, so if you manage to do it, please, share your experience, for example, as your own answer to your question.

Pavel Shved
I tried to build the Boost replacing g++ file with link to lsbc++. The result was that compilation of many libraries failed. I will try GCC 4.3 version, thank you for this information.
Alex Farber
@Alex, I hope that along with replacing link you also pointed `lsbc++` to real compiler, so it didn't recurse :-D. Anyway, you may also try to get help in the LSB mailing list: https://lists.linux-foundation.org/mailman/listinfo/lsb-discuss The mailing list format is more suitable for discussing concrete errors with error logs than StackOverflow.
Pavel Shved
Using GCC 4.3 did not help, I still cannot use lsbc++ compiler for third-party libraries. However, I have some results with LSB Application Checker. By adding missing libraries to my package, I managed to get 49 of 50 Linux distributions compatibility for the program using Boost ASIO library. Kind of success... Thank you for your help.
Alex Farber
+2  A: 

I've recently had call to do this, in the event that it's of use to anyone else these are the steps I followed:

  • Download and install the LSB SDK
  • Download a version of boost and extract to /opt/boost/boost_<version> (I used 1.43)
  • Make sure libbz2-dev is installed.
  • Bootstrap with
cd /opt/boost/boost_<version>
./bootstrap.sh --prefix=/opt/boost --without-libraries=python,mpi --without-icu
  • Edit /opt/boost/boost_<version>/project-config.jam and add the line
using gcc : : /opt/lsb/bin/lsbc++ : <cflags>-U_GNU_SOURCE <cxxflags>-U_GNU_SOURCE ;

near the top of the file. Note that this will fail if you have a using declaration in one of the other files bjam reads its configuration from, you can pass --debug-configuration to get an idea of which files it's reading.

  • Run
./bjam cflags=-fPIC cxxflags=-fPIC linkflags=-fPIC install

I didn't try to get either the python or MPI libraries working, nor did I try to get ICU working with the boost.regex library. The latter is probably a case of building static versions of the ICU libraries with the LSB toolset.

The -fPIC isn't strictly necessary for 32-bit Linux, but is required if you want to link static libraries into a shared library for 64-bit Linux.

The end result should be binaries in /opt/boost/lib and headers in /opt/boost/include, obviously you can modify the prefix to suit your own preferences. I still have a fair amount of work to do before I've ported all our code to the LSB, so I can't report on how well the certification process goes yet.

Adam Bowen
Interesting, thanks. Currently I am using auto tools to solve binary compatibility problem. I will keep your answer for future reference.
Alex Farber