![]() |
![]() |
|||||||||
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
|||||
Building the Boost regex library with C++Builder 6IntroductionBoost is a popular set of open source libraries that many C++ developers have added to their toolset. One of the most useful libraries in Boost is the regular expression library by Dr. John Maddock. The current version of boost (1.27 at the time of this writing), includes makefiles for building the regex library with BCB5 and the free BC55 command line compiler. However, Boost does not yet include a makefile for building the regex library with BCB6. The lack of a makefile isn't a huge issue. However, if you try to build the Boost regex library, you may run into additional problems. Some of those problems have to do with the fact that Borland has switched to STLPort in C++Builder6. The switch to STLPort is a welcome change. However, the maintainers of Boost have not yet taken this switch into account. As a result, some of the Boost libraries, including the regex library, fail to compile as is with BCB6. Thankfully, Boost is an open source library. While the regex library in Boost 1.27 does not compile with BCB6 as is, the changes necessary to make it compile are relatively minor. This article describes what files you need to change in order to build Boost regex with BCB6. You can download the patched boost files from the link at the bottom of the article. Summary of problemsProblem 1: --------------------- Boost does not include a BCB6 makefile for building the regex library. Solution: --------------------- Use the provided BCB5 makefile as a starting point. Problem 2: --------------------- The file boost\regex\config.hpp generates compiler errors when building the regex library. The errors are : Borland C++ 5.6 for Win32 Copyright (c) 1993, 2002 Borland ../src/c_regex_traits.cpp: Error E2272 ../../../boost/regex/config.hpp 481: Identifier expected Error E2272 ../../../boost/regex/config.hpp 483: Identifier expected Error E2272 ../../../boost/regex/config.hpp 484: Identifier expected Error E2272 ../../../boost/regex/config.hpp 497: Identifier expected Error E2272 ../../../boost/regex/config.hpp 521: Identifier expected Error E2272 ../../../boost/regex/config.hpp 522: Identifier expected Error E2272 ../../../boost/regex/config.hpp 523: Identifier expected Error E2272 ../../../boost/regex/config.hpp 524: Identifier expected Error E2272 ../../../boost/regex/config.hpp 525: Identifier expected *** 9 errors in Compile *** Solution: --------------------- The errors were caused because BOOST_NO_STDC_NAMESPACE was defined by boost\config\stdlib\stlport.hpp. The solution was to modify stlport.hpp to detect the presence of BCB6. If BCB6 is detected, BOOST_NO_STDC_NAMESPACE is not defined. /***** Original code- boost\config\stdlib\stlport.hpp line 78 *****/ // // STLport does a good job of importing names into namespace std::, // but doesn't always get them all, define BOOST_NO_STDC_NAMESPACE, since our // workaround does not conflict with STLports: // #if defined(__STL_IMPORT_VENDOR_CSTD) || defined(__STL_USE_OWN_NAMESPACE) || \ defined(_STLP_IMPORT_VENDOR_CSTD) || defined(_STLP_USE_OWN_NAMESPACE) # define BOOST_NO_STDC_NAMESPACE #endif /***** New code *****/ // // STLport does a good job of importing names into namespace std::, // but doesn't always get them all, define BOOST_NO_STDC_NAMESPACE, since our // workaround does not conflict with STLports: // // HJH note: // Borland switched to STLport in BCB6. Defining BOOST_NO_STDC_NAMESPACE with // BCB6 does cause problems. If we detect BCB6, then don't define // BOOST_NO_STDC_NAMESPACE #if !defined(__BORLANDC__) || (__BORLANDC__ < 0x560) #if defined(__STL_IMPORT_VENDOR_CSTD) || defined(__STL_USE_OWN_NAMESPACE) || \ defined(_STLP_IMPORT_VENDOR_CSTD) || defined(_STLP_USE_OWN_NAMESPACE) # define BOOST_NO_STDC_NAMESPACE #endif #endif Problem 3: --------------------- regex\config.hpp does not define BOOST_REGEX_USE_VCL for console mode apps that use the VCL. Solution: --------------------- Update!!! Originally, I had posted a change to config.hpp. That change would allow BOOST_REGEX_USE_VCL to be defined for console mode projects. The change that I posted works fine with BCB6, however, it causes major problems with the free BC55 command line compiler. The author of boost::regex, Dr Maddock, notified me of this fact. In order to remain compatible with BC55, regex\config.hpp should remain as it comes out of the box from boost. The original version of regex\config.hpp is still not compatible with BCB console mode projects that use the VCL, but there are easy workarounds for that. Here is the relevant code from regex\config.hpp. /***** Original code- boost\regex\config.hpp line 214 *****/ // // VCL support: // if we're building a console app then there can't be any VCL (can there?) // # if !defined(__CONSOLE__) && !defined(_NO_VCL) # define BOOST_REGEX_USE_VCL # endif This code attempts to define the macro BOOST_REGEX_USE_VCL for VCL projects. However, it won't define the value if you are compiling a VCL console mode project. This isn't a huge problem. If you are compiling a VCL console mode program and you want to use Boost::regex, just define the value yourself. You can define it in your makefile, or if you use the IDE, by adding BOOST_REGEX_USE_VCL to the list of conditional defines in your project options. This define is used to automatically link with the correct regex library. The automatic detection occurs in boost\regex\detail\regex_library_include.hpp. If you are using Boost::regex in a console mode VCL project, you will need to manually define BOOST_REGEX_USE_VCL if you want the automatic selection to work properly. If you don't, regex_library_include.hpp will attempt to link with the non VCL version of the regex library. Problem 4: --------------------- regex\detail\regex_library_include.hpp is not ready for use with BCB6. It detects the compiler version and links with files name bcb4re*.lib or bcb5re*.lib. In BCB6, it should link with files named bcb6re*.lib. Solution: --------------------- Modified regex_library_include.hpp to detect the BCB6 version of the compiler and link with libraries that have BCB6 in the name. /***** Original code- boost\regex\config.hpp lines 114-174 *****/ #if defined(__BORLANDC__) && !defined(BOOST_REGEX_BUILD_DLL) #if __BORLANDC__ < 0x550 /*** snip ***/ #else // C++ Builder 5: #ifdef BOOST_REGEX_USE_VCL #ifdef _RTLDLL #pragma comment(lib, "bcb5re300lv.lib") #else #pragma comment(lib, "bcb5re300v.lib") #endif #else // VCL /*** snip ***/ #endif // VCL #endif #endif //__BORLANDC__ /***** New code *****/ #if defined(__BORLANDC__) && !defined(BOOST_REGEX_BUILD_DLL) #if __BORLANDC__ < 0x550 // before BCB5 or free BC55 compiler #ifdef BOOST_REGEX_USE_VCL #ifdef _RTLDLL #pragma comment(lib, "bcb4re300lv.lib") #else #pragma comment(lib, "bcb4re300v.lib") #endif #else // VCL #ifdef _RTLDLL #ifdef __MT__ #pragma comment(lib, "bcb4re300lm.lib") #else // __MT__ #pragma comment(lib, "bcb4re300l.lib") #endif // __MT__ #else //_RTLDLL #ifdef __MT__ #pragma comment(lib, "bcb4re300m.lib") #else // __MT__ #pragma comment(lib, "bcb4re300.lib") #endif // __MT__ #endif // _RTLDLL #endif // VCL #elif __BORLANDC__ < 0x560 // C++Builder 5.x or the free BC55 compiler #ifdef BOOST_REGEX_USE_VCL #ifdef _RTLDLL #pragma comment(lib, "bcb5re300lv.lib") #else #pragma comment(lib, "bcb5re300v.lib") #endif #else // VCL #ifdef _RTLDLL #ifdef __MT__ #pragma comment(lib, "bcb5re300lm.lib") #else // __MT__ #pragma comment(lib, "bcb5re300l.lib") #endif // __MT__ #else //_RTLDLL #ifdef __MT__ #pragma comment(lib, "bcb5re300m.lib") #else // __MT__ #pragma comment(lib, "bcb5re300.lib") #endif // __MT__ #endif // _RTLDLL #endif // VCL #else // C++ Builder 6: #ifdef BOOST_REGEX_USE_VCL #ifdef _RTLDLL #pragma comment(lib, "bcb6re300lv.lib") #else #pragma comment(lib, "bcb6re300v.lib") #endif #else // VCL #ifdef _RTLDLL #ifdef __MT__ #pragma comment(lib, "bcb6re300lm.lib") #else // __MT__ #pragma comment(lib, "bcb6re300l.lib") #endif // __MT__ #else //_RTLDLL #ifdef __MT__ #pragma comment(lib, "bcb6re300m.lib") #else // __MT__ #pragma comment(lib, "bcb6re300.lib") #endif // __MT__ #endif // _RTLDLL #endif // VCL #endif #endif //__BORLANDC__ Problem 5: --------------------- The boost source files don't include vcl.h, which causes a #pragma commment(lib) comment in sysmac.h to be missed. This results in unresolved linker errors when building the VCL version of the regex DLL. This is an existing problem that BCB5 users might want to look at. Solution: --------------------- One solution would be to add a #include for vcl.h or system.hpp to one of the regex header files. Such an include would have to be conditionally compiled in when __BORLANDC__ is detected and when the VCL is detected. Another solution is to just link with the correct lib files in the make file. I chose to link with the lib files in BCB6.mak. When building the VCL version of the regex DLL, the makefile passes rtl.lib and vcle.lib to the linker. Problem 6: --------------------- The BCB5 makefile invokes tlib using the + option. This option does not replace a module if it already exists in the libary. This is an existing problem that BCB5 users might want to look at. Solution: --------------------- Switched from + to -+ instead, which replaces the module in the library if it exists. Problem 7: --------------------- The BCB5 makefile created files with BCB5 in the name. It also placed all output in a directory called BCB5. Solution: --------------------- Replaced all occurrences of BCB5 in the makefile with BCB6. Notes
Note 1: Ed James-Beckham from Borland has submitted a BCB6 compatible
version of boost\config\compilers\borland.hpp. His changes are not in
the Boost 1.27 download, but you can obtain his changes from the CVS repository
for boost. The newest version of borland.hpp is available
here.
Downloads
| ||||||||||
All rights reserved. |