Boost logo

Boost Users :

Subject: [Boost-users] [Regex] Source-only link error in MSVC
From: dtexg_at_[hidden]
Date: 2009-05-18 21:33:38


I'm trying to include the Boost Regex source in a Visual C++
project, but I get the following linker error: (indented for

error LNK2019: unresolved external symbol
"private: class boost::basic_regex<
  struct boost::regex_traits<
    class boost::w32_regex_traits<char> > > &
__thiscall boost::basic_regex<
  struct boost::regex_traits<
    class boost::w32_regex_traits<char> > >::
  char const *,
  char const *,
  unsigned int)"
referenced in function "public: class boost::basic_regex<
  struct boost::regex_traits<
    class boost::w32_regex_traits<char> > > &
__thiscall boost::basic_regex<
  struct boost::regex_traits<
    class boost::w32_regex_traits<char> > >::
  char const *,
  char const *,
  unsigned int)"

Here are the steps I'm taking:

I downloaded the latest Boost (, and extracted it
all into its own directory; I've tried extracting with both the
built-in Windows Zip Folder support and the latest WinRAR.

I did not do any making (nmake) or building on the Boost source --
after extracting, I don't touch this directory directly at all.

In both Visual Studio 2005 and Visual C++ 2008 Express Edition
(, I created a new empty
console project, and I added a new .cpp file to the project.

I went to Project -> Properties, Configuration Properties -> C/C++ -
> General: Additional Include Directories, and (for the
"Active(Debug)" configuration) added the full path of the directory
containing the source, so that "boost" is a subdirectory in the
selected directory.

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
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

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.


Free information on Digital Photography. Click Now!

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