EXC BAD ACCESS错误在Xcode上构建QuantLib C ++程序

时间:2015-02-17 01:16:21

标签: c++ boost quantlib

我使用clang ++在本地计算机(Mac OS X 10.10.1)上构建了Boost(1.57)。我还建立了量化金融库QuantLib。 QuantLib在其实现中引用了Boost。

我在XCode中创建了一个简单的C ++程序来测试QuantLib库。代码如下:

#include <iostream>
#include <ql/quantlib.hpp>

int main(int argc, const char * argv[]) {        
    std::cout << "Hello, World!\n";
    return 0;
}

此代码构建正常(尽管有一些我现在可以忽略的警告)。但是,在运行代码时,我在Boost库(erf.hpp)中得到一个线程异常,如下所示:

#0  0x00000001003f73b7 in long double boost::math::detail::erf_imp<long double, boost::math::policies::policy<boost::math::policies::promote_float<false>, boost::math::policies::promote_double<false>, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy> >(long double, bool, boost::math::policies::policy<boost::math::policies::promote_float<false>, boost::math::policies::promote_double<false>, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy> const&, mpl_::int_<64> const&) at /usr/local/include/boost/math/special_functions/erf.hpp:423
#1  0x00000001003f8928 in boost::math::tools::promote_args<long double, float, float, float, float, float>::type boost::math::erf<long double, boost::math::policies::policy<boost::math::policies::promote_float<false>, boost::math::policies::promote_double<false>, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy> >(long double, boost::math::policies::policy<boost::math::policies::promote_float<false>, boost::math::policies::promote_double<false>, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy> const&) [inlined] at /usr/local/include/boost/math/special_functions/erf.hpp:1081
#2  0x00000001003f8916 in boost::math::detail::erf_initializer<long double, boost::math::policies::policy<boost::math::policies::promote_float<false>, boost::math::policies::promote_double<false>, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy>, mpl_::int_<64> >::init::do_init(mpl_::int_<64> const&) at /usr/local/include/boost/math/special_functions/erf.hpp:1009
#3  0x00000001003f987b in boost::math::detail::erf_initializer<long double, boost::math::policies::policy<boost::math::policies::promote_float<false>, boost::math::policies::promote_double<false>, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy>, mpl_::int_<64> >::init::init() [inlined] at /usr/local/include/boost/math/special_functions/erf.hpp:994
#4  0x00000001003f9876 in boost::math::detail::erf_initializer<long double, boost::math::policies::policy<boost::math::policies::promote_float<false>, boost::math::policies::promote_double<false>, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy>, mpl_::int_<64> >::init::init() [inlined] at /usr/local/include/boost/math/special_functions/erf.hpp:995
#5  0x00000001003f9876 in __cxx_global_var_init at /usr/local/include/boost/math/special_functions/erf.hpp:1038
#6  0x00007fff5fc12ceb in ImageLoaderMachO::doModInitFunctions(ImageLoader::LinkContext const&) ()
#7  0x00007fff5fc12e78 in ImageLoaderMachO::doInitialization(ImageLoader::LinkContext const&) ()
#8  0x00007fff5fc0f871 in ImageLoader::recursiveInitialization(ImageLoader::LinkContext const&, unsigned int, ImageLoader::InitializerTimingList&, ImageLoader::UninitedUpwards&) ()
#9  0x00007fff5fc0f806 in ImageLoader::recursiveInitialization(ImageLoader::LinkContext const&, unsigned int, ImageLoader::InitializerTimingList&, ImageLoader::UninitedUpwards&) ()
#10 0x00007fff5fc0f6f8 in ImageLoader::processInitializers(ImageLoader::LinkContext const&, unsigned int, ImageLoader::InitializerTimingList&, ImageLoader::UninitedUpwards&) ()
#11 0x00007fff5fc0f969 in ImageLoader::runInitializers(ImageLoader::LinkContext const&, ImageLoader::InitializerTimingList&) ()
#12 0x00007fff5fc02245 in dyld::initializeMainExecutable() ()
#13 0x00007fff5fc05be1 in dyld::_main(macho_header const*, unsigned long, int, char const**, char const**, char const**, unsigned long*) ()
#14 0x00007fff5fc01276 in dyldbootstrap::start(macho_header const*, int, char const**, long, macho_header const*, unsigned long*) ()
#15 0x00007fff5fc01036 in _dyld_start ()

更具体地说,它在erf.hpp文件中失败;

  else
  {
     // Max Error found at long double precision =   1.623299e-20
     // Maximum Deviation Found:                     4.326e-22
     // Expected Error Term:                         -4.326e-22
     // Maximum Relative Change in Control Points:   1.474e-04
     static const T Y = 1.044948577880859375f;
     static const T P[] = {


/** THREAD EXCEPTION HERE **/        
BOOST_MATH_BIG_CONSTANT(T, 64, 0.0834305892146531988966),// FAILS HERE WITH EXC_BAD_ACCESS    


        BOOST_MATH_BIG_CONSTANT(T, 64, -0.338097283075565413695),
        BOOST_MATH_BIG_CONSTANT(T, 64, -0.0509602734406067204596),
        BOOST_MATH_BIG_CONSTANT(T, 64, -0.00904906346158537794396),
        BOOST_MATH_BIG_CONSTANT(T, 64, -0.000489468651464798669181),
        BOOST_MATH_BIG_CONSTANT(T, 64, -0.200305626366151877759e-4),
     };
     static const T Q[] = {    
        BOOST_MATH_BIG_CONSTANT(T, 64, 1.0),
        BOOST_MATH_BIG_CONSTANT(T, 64, 0.455817300515875172439),
        BOOST_MATH_BIG_CONSTANT(T, 64, 0.0916537354356241792007),
        BOOST_MATH_BIG_CONSTANT(T, 64, 0.0102722652675910031202),
        BOOST_MATH_BIG_CONSTANT(T, 64, 0.000650511752687851548735),
        BOOST_MATH_BIG_CONSTANT(T, 64, 0.189532519105655496778e-4),
     };
     result = z * (Y + tools::evaluate_polynomial(P, T(z * z)) / tools::evaluate_polynomial(Q, T(z * z)));
  }

从SO上的另一篇文章看,我认为这可能是一个Xcode问题,但我没有另一台机器与另一个操作系统进行验证。无论如何,我不明白为什么Xcode会干扰这个级别的代码,所以我认为这可能是因为铿锵而只是猜想。任何帮助解决这个问题或阐明问题的人都将不胜感激。


更新

删除#include <ql/experimental/all.hpp>允许程序运行。问题是为什么在Boost中包含此标头导致运行时失败。

0 个答案:

没有答案