Boost logo

Boost Users :

Subject: Re: [Boost-users] [Regex] Source-only link error in MSVC
From: John Maddock (john_at_[hidden])
Date: 2009-05-19 04:42:57

> I wrote the following code:
> #include <boost/regex.hpp>
> int main()
> {
> boost::regex r("a");
> return 0;
> }
> Everything compiles, but linking fails with the above error. The
> same error results if I try this:
> boost::regex * p = new boost::regex("a");
> Or if I use boost::wregex, or
> boost::basic_regex<char,boost::regex_traits<char,boost::w32_regex_tr
> aits<char>>>, etc. Also, the outcome is the same whether I #define
> whether I define them in the .cpp or in Project -> Properties,
> Configuration Properties -> C/C++ -> Preprocessor: Preprocessor
> Definitions, and whether I #include <boost/regex.hpp> or
> <boost/regex/v4/regex.hpp>, and whether I use Debug or Release
> configuration.
> If I put a #error by the do_assign implementation in
> boost/regex/v4/basic_regex.hpp, it gets hit, so the implementation
> isn't being #if'ed away somehow.
> It will build successfully if, in the .cpp file in which main()
> resides, I write an implementation and replace all the template
> arguments, but besides being vulgar, this kludge also fails (with
> compiler errors) if I try to copy-and-paste the full implementation
> from basic_regex.hpp, so it's untenable as a workaround.
> In a post from 2006, John wrote, "if you are doing something, umm,
> strange, and you can't track down the cause of the error, you can
> always just add the regex source directly to your application," but
> I've not seen this successfully demonstrated in Visual C++. I'm
> just looking for an absolutely parsimonious way to add Boost Regex
> to a VC++ project.

Well, you need to do what I said, not what you did ;-)

Take all the .cpp files in libs/regex/src and add them to your console
project's source, build and voila, it should all work.

BTW use BOOST_REGEX_NO_LIB not BOOST_REGEX_SOURCE in your source files, as
the latter is for private regex use only and most certainly does not do what
you think it does.

In point of fact I do this all the time, so it definitely does work.

HTH, John.

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at