开发者

Problem with using Boost::Regex (Console just freezes up)

开发者 https://www.devze.com 2023-03-25 18:56 出处:网络
For some reason boost::regex overloads my application and it freezes without an error, but it compiles fine. For instance this code f开发者_运维技巧ails flatly. What am I doing wrong? I updated to boo

For some reason boost::regex overloads my application and it freezes without an error, but it compiles fine. For instance this code f开发者_运维技巧ails flatly. What am I doing wrong? I updated to boost 1.47 to see if it was a DLL error, but it still doesn't work. Can I get an example program to test out the boost::regex?

static const boost::regex expression("^[0-9]+");
std::string str = "123a1";
std::cout << boost::regex_search(str.c_str(), expression);


The first thing to do is to see if your version of Boost supports threading. Compiling and running something like the following should tell you that:

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

int
main()
{
#ifdef BOOST_HAS_THREADS
    std::cout << "Boost has threads" << std::endl;
#else
    std::cout << "Boost doesn't support threads" << std::endl;
#endif
    return 0;
}

The second thing is to verify that all of the requirements are met. You've just posted the actual lines, not the context in which they are executed. If the first line is in namespace scope, you should be OK (unless you've started threading in constructors to static objects, before entering main: don't do that). If the first line has block scope (i.e. is in a function), then you are only OK if the first call to this function occurs before threading starts. (From what I understand, with g++, you should be OK even if the first line has block scope, but I'm not sure.)


After some work I deleted the boost installation from BoostPro and compiled boost myself and now it works. The problem was that BoostPro did not install all of the DLL's and I thought when it asked me for a missing DLL that BoostPro named them wrong (boost_regex-vc100-mt-1_47.dll instead of boost_regex-vc100-mt-gd-1_47.dll). After getting the correct DLL everything works fine. Thank you for your help troubleshooting this!

0

精彩评论

暂无评论...
验证码 换一张
取 消