Search code examples
c++boostboost-build

How do I compile boost using a specific VC++ Runtime?


I'm trying to get a consistent VC++ runtime for distribution, but I cannot find anything forcing boost/bjam to cooperate.

I have successfully compiled libcurl and UnitTest++ with the method in this link.

Avoiding problems with VC2005 SP1 Security update KB971090

The general strategy is to include this header in all the cpp files.

#ifndef __midl
#define _SXS_ASSEMBLY_VERSION "8.0.50727.762"
#define _CRT_ASSEMBLY_VERSION _SXS_ASSEMBLY_VERSION
#define _MFC_ASSEMBLY_VERSION _SXS_ASSEMBLY_VERSION
#define _ATL_ASSEMBLY_VERSION _SXS_ASSEMBLY_VERSION
#ifdef __cplusplus
extern "C" {
#endif
__declspec(selectany) int _forceCRTManifest;
__declspec(selectany) int _forceMFCManifest;
__declspec(selectany) int _forceAtlDllManifest;
__declspec(selectany) int _forceCRTManifestRTM;
__declspec(selectany) int _forceMFCManifestRTM;
__declspec(selectany) int _forceAtlDllManifestRTM;
#ifdef __cplusplus
}
#endif
#endi

b2 has options for setting cxxflags, though they do not seem to honor my /FI compile option to use the header and force the correct runtime. I assume that they are using something else. I suppose boost doesn't use the msvc flags?

I would like to compile boost with 8.0.50727.762 specifically.


Solution

  • Apparently bjam is persnickety about which flags have leading -- dashes.

    bjam ^
        toolset=msvc-8.0 ^
        link=static ^
        cxxflags=/FI"C:/boost_1_44_0/sxs_header.h" ^
        --with-thread ^
        --with-date_time ^
        --with-system ^
        -d2
    

    Will produce the correct compiler flags:

    file bin.v2\libs\thread\build\msvc-8.0\release\link-static\threading-multi\win32\thread.obj.rsp
    "libs\thread\src\win32\thread.cpp"
     -Fo"bin.v2\libs\thread\build\msvc-8.0\release\link-static\threading-multi\win32\thread.obj"
        -TP
     /O2
     /Ob2
     /W3
     /GR
     /MD
     /Zc:forScope
     /Zc:wchar_t
     /wd4675
     /EHs
     /FIC:/boost_1_44_0/sxs_header.h
     -c
    
    -DBOOST_ALL_NO_LIB=1
    
    -DBOOST_THREAD_BUILD_LIB=1
    
    -DNDEBUG
    
    "-I."
    
    compile-c-c++ bin.v2\libs\thread\build\msvc-8.0\release\link-static\threading-multi\win32\thread.obj
    
        call "C:\Program Files (x86)\Microsoft Visual Studio 8\VC\vcvarsall.bat" x86 >nul
    cl /Zm800 -nologo @"bin.v2\libs\thread\build\msvc-8.0\release\link-static\threading-multi\win32\thread.objp"
    
    thread.cpp
    

    Which you can verify by creating a test app that uses something that requires boost to link, then checking its manifest file in the intermediates directory.

    <?xml version='1.0' encoding='UTF-8' standalone='yes'?>
    <assembly xmlns='urn:schemas-microsoft-com:asm.v1' manifestVersion='1.0'>
      <dependency>
        <dependentAssembly>
          <assemblyIdentity type='win32' name='Microsoft.VC80.CRT' version='8.0.50727.762' processorArchitecture='x86' publicKeyToken='1fc8b3b9a1e18e3b' />
        </dependentAssembly>
      </dependency>
    </assembly>
    

    You should only see the one assemblyIdentity with the correct version, otherwise you'll usually have a couple with higher numbers.