C++ and STL
  Common Issues
  Destructor
  regex
  string
 MFC
  CButton
  CDialog
  CEdit
  CInternetSession
  CWinThread
  CWnd
 MS VS FAQ
  Compiling, building
  Debugging
  Editor
  Settings
 Win32, API
  Console
  File System
  Graphics
  Internet functions
  Kernel objects
  Security
  Sound
  Thread, process
  Window
 Windows NT/2K*
  Logon, logoff...
  Networking
  Service Packs
 | About
  About
  Links & Freeware

Powered by
CoderTown



Adding regular expressions support for VC++ project

Regular expressions is an essential part of nowadays programming. Regular expressions is a powerful tool for text and data parsing and manipulating of any kind. Forget about hassles and head scratching while writing another parsing function. Get familiar with regular expressions and feel the difference!

C++ standard does not declare regular expressions support so far (2004). But there are some libraries out there which implement required functionality pretty well. Regex from boost.org is one of them. Let's check how you can add a regular expressions support to your project using boost.org Regex library.

Boost.org is an Open Source project and has a bunch of libraries within itself. You can download its source code from sourceforge.net. Do not search for binaries, you have to build them yourself (if required).

Here I'll describe my experience using Boost Regex for Visual C++ project. I was using particularly Microsoft Visual C++ .NET, version 7.1 (as a part of Microsoft Visual Studio .NET 2003).

Step 1. Download the library source code (*.zip file). At the moment of writing Boost library has version 1.31.0 released Feb. 2004. Usually the archive includes all libraries from Boost project and is rather big. It also includes documentation and installation instructions. Extract the file to any temporary location. You'll find some folders and files, we'll need only some of them.

   BOOST
   DOC
   LIBS
   MORE
   PEOPLE
   STATUS
   TOOLS
   boost.css
   boost-build.jam
   "c++boost.gif"
   google_logo_40wht.gif
   index.htm
   Jamfile
   Jamfile.v2
   Jamrules
   LICENSE_1_0.txt
   project-root.jam
   README
   rst.css

Step 2. Copy boost folder to your include folder which is usually something like this:

\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include

Starting from this point you can include Boost regex header into your source code like this:

   #include "boost/regex.hpp"

The code will compile but won't link yet. To get it linked and running we need *.lib files and *.dll-s if library will be linked dynamically. Remember: Boost is not only regualar expressions. There is a bunch of useful stuff in it like iterators, smart pointers, algorithms, math and more ...

Step 3. Copy libs folder to your include folder too. (Not to lib folder!) We'll need it to build *.lib and *.dll files later.

Step 4. To build lib and dll files we need nmake utility form your VC7\bin folder and vc71.mak file located in just copied \libs\regex\build\ folder. Depending on your version of VC++, you should use proper MAK file. Before using it we need to check two things: make sure that VC environment variables are set and set properly; and that MAK file has valid paths inside itself.

Locate vcvars32.bat file in your \VC7\bin folder. Use this file as a reference what variables has to be set. Actually we need 3 variables set properly: %PATH%, %INCLUDE% and %LIB%. Just starting the bat file might have no effect as long as you are working in Windows 2000 or XP. You have to set the variables manually if they are not set yet. Go to Control Panel, System, choose Advanced tab and press Environment Variables...

Created: 2004-10-04
Updated: 2004-10-05

Google
 
Web visualcpp.net
msdn.microsoft.com codeguru.com