Thursday, May 17, 2007

Building Boost 1.34 for x86, x64 and IA64

The new version of Boost library has been released recently. Since we have released ApexSQL Log 2005.04 just the other day, we can now migrate our source base to Boost 1.34. This post will deal with building of Boost static libraries for side-by-side compilation and linking of x86, x64 and IA64 libraries. This is now much easier than it was in Boost 1.33 but there is still some work to be done.

1. Download Boost and Boost.Jam from here.
2. Put Boost.Jam binary into a directory on your PATH.
3. Uncompress Boost library into a directory of your choice.
4. There is an error in one of Boost build files that needs to be fixed before compiling for IA64 architecture:
  1. Go to boost_1_34_0\tools\build\v2\tools folder.
  2. Open msvc.jam in your favorite editor (mine is by *far* Visual Studio itself)
  3. Replace all instances of "x86_IPF" with "x86_ia64" (there should be two)
There is also an omission in the same file and native x64 compiler will be used only on boxes with %PROCESS_IDENTIFIER% matching AMD64. So if you have Intel based x64 CPU build will be done with x86-x64 cross-compiler. It's just slower but the results are the same. If it bothers you, you should be able to fix it easily.

5. Go to command prompt, change directory to boost_1_34 and build Boost library for all three architectures.
  • For x86:
bjam msvc architecture=x86 stage
  • For x64:
bjam msvc architecture=x86 address-model=64 stage
  • For IA64:
bjam msvc architecture=ia64 stage

6. Install x86 libraries:

bjam msvc architecture=x86 install

By default Boost will install its include and lib files into C:\Boost\lib and C:\Boost\include\boost-1_34. The problem with this is that if want to install x64 or IA64 static library files these will overwrite x86 static library files already installed. To avoid this we need to move all x86 static libraries to C:\Boost\lib\x86 (this is my solution - obviously other solutions are possible) so that these aren't overwritten by subsequent installations.

7. Install x64 libraries:

bjam msvc architecture=x86 address-model=64 install

Again, move these libraries from C:\Boost\lib to C:\Boost\lib\x64.

8. Install IA64 libraries:

bjam msvc architecture=architecture=ia64 install

Now move these libraries C:\Boost\lib to C:\Boost\lib\ia64.

9. Adapt your Visual C++ projects so that:
  • x86 platform links libraries from C:\Boost\lib\x86
  • x64 platform links libraries from C:\Boost\lib\x64
  • ia64 platform links libraries from C:\Boost\lib\ia64
That's it! You should now be ready to use Boost libraries for binaries on all three Windows platforms.

Update: Fixed a typo in "For IA64" build statement.

2 comments:

Unknown said...

I am having problems with step 5.

First, there may be a typo in "For IA64".

Second and more importantly, I got several failed(32) and skipped(21) targets while running the bjam for x64.

Is this serious or can I just move on?

I am trying to get this working for x64.

Any help appreciated.

Thanks.

Ivan Erceg said...

Yes, there was a typo. I have fixed it now - thanks.

The skipped targets are probably Boost.Python which is built only if Python installed and configured. Depending on what you intend to do this may or may not matter to you.

But failed targets are not normal I think so I would look into that further.