[Regex] Source-only link error in MSVC

Hi, I'm trying to include the Boost Regex source in a Visual C++ project, but I get the following linker error: (indented for legibility) error LNK2019: unresolved external symbol "private: class boost::basic_regex< char, struct boost::regex_traits< char, class boost::w32_regex_traits<char> > > & __thiscall boost::basic_regex< char, struct boost::regex_traits< char, class boost::w32_regex_traits<char> > >:: do_assign( char const *, char const *, unsigned int)" (?do_assign@?$basic_regex@DU?$regex_traits@DV?$w32_regex_traits@D@bo ost@@@boost@@@boost@@AAEAAV12@PBD0I@Z) referenced in function "public: class boost::basic_regex< char, struct boost::regex_traits< char, class boost::w32_regex_traits<char> > > & __thiscall boost::basic_regex< char, struct boost::regex_traits< char, class boost::w32_regex_traits<char> > >:: assign( char const *, char const *, unsigned int)" (?assign@?$basic_regex@DU?$regex_traits@DV?$w32_regex_traits@D@boost @@@boost@@@boost@@QAEAAV12@PBD0I@Z) Here are the steps I'm taking: I downloaded the latest Boost (boost_1_39_0.zip), 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 (http://www.microsoft.com/express/vc/), 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:
#define BOOST_REGEX_SOURCE
#include

I wrote the following code:
#define BOOST_REGEX_SOURCE #include
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
>, etc. Also, the outcome is the same whether I #define BOOST_REGEX_SOURCE, BOOST_REGEX_NO_LIB, or BOOST_ALL_NO_LIB, and whether I define them in the .cpp or in Project -> Properties, Configuration Properties -> C/C++ -> Preprocessor: Preprocessor Definitions, and whether I #include or , 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.
participants (2)
-
dtexg@hush.com
-
John Maddock