Application crashes when using Boost* Libraries V1_40_0 built with Intel(R) C++ Compilers 11.x for Windows*

Submit New Article

December 3, 2009 9:00 PM PST



Problem : 

Some applications linked with Boost* libraries version 1_40_0 built with the Intel(R) C++ Compilers 11.0 and 11.1 may experience runtime errors.  The programs run fine when they are built with the /MDd or /MTd options.  They also run fine when they are built with the Microsoft* Compiler with or without the above options.

Below are two sample programs that exhibit the runtime error:

Example 1

#include <boost/regex.hpp>
#include <iostream>
#include <string>

int main()
{
   std::string line;
   boost::regex pattern("^Subject:(Re: |Aw: )*(.*)");

   while(std::cin)
   {
      std::getline(std::cin,line);
      boost::smatch matches;
      if(boost::regex_match(line,matches,pattern))
std::cout<<matches[2]<<std::endl;
} }


> icl /EHsc t1.cpp /IC:\boost_1_40_0 /link /LIBPATH:C:\boost_1_40_0\stage\lib
Intel(R) C++ Compiler Professional for applications running on IA-32, Version 11.1 Build 20090930 Package ID: w_cproc_p_11.1.048
Copyright (C) 1985-2009 Intel Corporation. All rights reserved.

When the above program is run it reports:
Assertion failed: px != 0, file C:\boost_1_40_0\boost/smart_ptr/shared_ptr.hpp,
line 412

Example 2

Intel(R) C++ Compiler Professional for applications running on IA-32, Version 11.1    Build 20090511 Package ID: w_cproc_p_11.1.035
Copyright (C) 1985-2009 Intel Corporation.  All rights reserved.

#include <iostream>
#include <boost/program_options.hpp>
using namespace std;
using namespace boost::program_options;

int main(int argc, char* argv[])
{
 options_description opt("option");
 opt.add_options()
   ("help,h",                                  "help");

  cout << opt << endl;
  return 0;
}

> icl /EHsc t2.cpp /IC:\boost_1_40_0 /link /LIBPATH:C:\boost_1_40_0\stage\lib


When the above program is run it crashes due to unhandled access violation exception at:
> t2.exe!shared_count::~shared_count()  Line 217 + 0x3 bytes C++


Environment : 
All Windows* Operating Systems


Root Cause : 

When building using the Intel compiler, the macro -D_SECURE_SCL is defined to 0.  When building with the Microsoft compiler, this is not specified, and defaults to a value of 1.  This is what is largely contributing to the difference in the run-time behavior between the icl and cl generated codes.  The macro was defined differently in the configuration file to disable Microsoft "secure" overloads in Dinkumware* libraries since they caused compile errors with Intel compiler versions 9.x and 10.x  This is no longer an issue  starting with Intel compiler version 11.0 and higher. 

Resolution : 

The solution is to modify the jam file in your boost installation under tools\build\v2\tools\intel-win.jam and change the definition to _SECURE_SCL=1 and rebuild the Boost libraries like:

C:\boost_1_40_0>bjam --clean-all --build-dir=c:\boost_1_40_0 toolset=intel --build-type=complete stage
C:\boost_1_40_0>bjam --build-dir=c:\boost_1_40_0 toolset=intel --build-type=complete stage


Do you need more help?


This article applies to: Intel® C++ Compiler for Windows* Knowledge Base,   Intel® Parallel Composer Knowledge Base