fatal error LNK1104: cannot open file 'libboost_regex-vc90-mt-gd-1_42.lib'
Asked Answered
C

4

7

i'm trying to use boost regex within my program the problem is i get this error... the only installation step i did was to add: "C:\Program Files\boost\boost_1_42" into the Additional Include Directories...

i'm using VS2008...

trying to implement this:

#include <iostream>
#include <string>
#include <boost/regex.hpp>

using namespace std;

int main( ) {

   std::string s, sre;
   boost::regex re;
   boost::cmatch matches;

   while(true)
   {
      cout << "Expression: ";
      cin >> sre;
      if (sre == "quit")
      {
         break;
      }

      cout << "String:     ";
      cin >> s;

      try
      {
         // Assignment and construction initialize the FSM used
         // for regexp parsing
         re = sre;
      }
      catch (boost::regex_error& e)
      {
         cout << sre << " is not a valid regular expression: \""
              << e.what() << "\"" << endl;
         continue;
      }
      // if (boost::regex_match(s.begin(), s.end(), re))
      if (boost::regex_match(s.c_str(), matches, re))
      {
         // matches[0] contains the original string.  matches[n]
         // contains a sub_match object for each matching
         // subexpression
         for (int i = 1; i < matches.size(); i++)
         {
            // sub_match::first and sub_match::second are iterators that
            // refer to the first and one past the last chars of the
            // matching subexpression
            string match(matches[i].first, matches[i].second);
            cout << "\tmatches[" << i << "] = " << match << endl;
         }
      }
      else
      {
         cout << "The regexp \"" << re << "\" does not match \"" << s << "\"" << endl;
      }
   }
}

what seems to be the problem ? any additional settings should be made ?

Callison answered 16/2, 2010 at 16:0 Comment(0)
H
14

Some Boost libraries have to be built; this is one of them. Here's how you can build them:

Make a new file called boost_build.bat, and inside put:

bjam toolset=msvc-9.0 variant=release threading=multi link=static define=_SECURE_SCL=0 define=_HAS_ITERATOR_DEBUGGING=0
bjam toolset=msvc-9.0 variant=debug threading=multi link=static

Note 9.0 refers to VS 2008. (10.0 for 2010, 8.0 for 2005, 7.1 for 2003, 6.0 for, well, 6.0). Once you've done this:

  1. Extract build_boost.bat to <boost_root>

  2. Go to: <boost_root>\tools\jam And run build_dist.bat

  3. Copy <boost_root>\tools\jam\stage\bin.ntx86\bjam.exe to <boost_root>

  4. Run boost_build.bat

  5. Libraries are located in <boost_root>\stage\lib

Note, this is my own method. I would love if someone chimed in an easier way, or some link from Boost; it seems it's difficult to find proper build instructions from Boost.

Once it's built, make sure you let the compiler know where the libraries are in your VC Directories (the Library Paths); add "<boost_root>\stage\lib".


In the bjam defines, I have _SECURE_SCL=0 _HAS_ITERATOR_DEBUGGING=0 for Release. This disables all iterator checking in Release builds, for a speed improvement.

Hyperon answered 16/2, 2010 at 16:6 Comment(7)
still same error... 1>LINK : fatal error LNK1104: cannot open file 'libboost_regex-vc90-mt-gd-1_42.lib' did exactly as u said...Callison
ok it works... added to the linker "C:\Program Files\boost\boost_1_42\stage\lib\libboost_regex-vc90-mt-gd-1_42.lib"Callison
_HAS_ITERATOR_DEBUGGING only applies to Debug builds. Regarding _SECURE_SCL, though, have you encountered problems mixing libraries that have it enabled with libraries that have it disabled?Renter
@James: Ah, didn't know that about _HAS.... And for your second question, I wouldn't know. I disable it in my release builds in things that use Boost, so they match.Hyperon
connect.microsoft.com/VisualStudio/feedback/details/524141/…Plurality
@darid: Thank you; I hadn't seen that (from the link: "Additionally, _SECURE_SCL defaults to 0 in release mode in VC10." Wonderful; let's change it again and confuse everyone!) @GMan: As a heads-up concerning _HAS_ITERATOR_DEBUGGING (in debug builds only, obviously), there's also a really fun bug in the VC9 stringstream implementation when it is disabled (connect.microsoft.com/VisualStudio/feedback/details/435483). That bug has caused me ceaseless grief.Renter
It seems the default download contains a boostrap.bat and then after that bjam.exe file which takes care of all the building for us...Tractable
L
2

On Windows, the easiest way to get boost binary libraries is to run the installer from BoostPro consulting. Be sure to select your version of Visual Studio and check the box for the regex library during the install.

Larimer answered 18/9, 2011 at 12:53 Comment(1)
The default source install would be easy enough if they didn't arbitrarily do dumb things like make a bat file you click that DOESN'T do the whole job. Why is it that Programmers can't make tools that just work the first time, and which follow the principle of least amazement. BoostPro's installers are fine, I'm just complaining about the boost website's zip file downloads. It seems to me they should just drop them and put a link over to a real install. Of course, BoostPro is dead or dying and so this answer is no longer going to be current.Revolute
G
1

Have you installed the multithreading debug version of Boost? If not, please do so. Otherwise check your library path (in the project preferences) so that it includes the path to the file mentioned in the error message.

Gunar answered 16/2, 2010 at 16:3 Comment(0)
N
0

I'm not sure about the define settings, but I was able to get boost to build with MSVC 9.0 by running the <boostroot>\bootstrap batch file, then editing <boostroot>\project-config.jam file as follows. Change the line:

using mvsc

to:

using msvc : 9.0 : cl.exe

then running .\b2 install and the boost headers and libraries were built and installed to c:\boost.

Nolde answered 23/6, 2012 at 6:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.