【问题标题】:fatal error LNK1104: cannot open file 'libboost_regex-vc90-mt-gd-1_42.lib'致命错误 LNK1104:无法打开文件“libboost_regex-vc90-mt-gd-1_42.lib”
【发布时间】:2011-01-17 11:12:47
【问题描述】:

我正在尝试在我的程序中使用 boost 正则表达式 问题是我得到这个错误...... 我做的唯一安装步骤是添加:“C:\Program Files\boost\boost_1_42” 进入附加包含目录...

我正在使用 VS2008...

试图实现这个:

#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;
      }
   }
}

似乎是什么问题?是否需要进行其他设置?

【问题讨论】:

    标签: c++ boost-regex


    【解决方案1】:

    必须构建一些 Boost 库;这是其中之一。以下是构建它们的方法:

    创建一个名为 boost_build.bat 的新文件,并在里面放置:

    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
    

    注意 9.0 指的是 VS 2008。(2010 年为 10.0,2005 年为 8.0,2003 年为 7.1,6.0 为 6.0)。完成此操作后:

    1. build_boost.bat提取到&lt;boost_root&gt;

    2. 转到: &lt;boost_root&gt;\tools\jam 然后运行build_dist.bat

    3. 复制&lt;boost_root&gt;\tools\jam\stage\bin.ntx86\bjam.exe&lt;boost_root&gt;

    4. 运行boost_build.bat

    5. 库位于&lt;boost_root&gt;\stage\lib

    注意,这是我自己的方法。如果有人以更简单的方式或来自 Boost 的链接,我会喜欢;似乎很难从 Boost 中找到正确的构建说明。

    一旦构建完成,请确保让编译器知道库在 VC 目录中的位置(库路径);添加“&lt;boost_root&gt;\stage\lib”。


    bjam 定义中,我有_SECURE_SCL=0 _HAS_ITERATOR_DEBUGGING=0 用于发布。这会禁用发布版本中的所有迭代器检查,以提高速度。

    【讨论】:

    • 还是同样的错误... 1>链接:致命错误 LNK1104:无法打开文件 'libboost_regex-vc90-mt-gd-1_42.lib' 完全按照你说的...
    • 好的,它可以工作...添加到链接器“C:\Program Files\boost\boost_1_42\stage\lib\libboost_regex-vc90-mt-gd-1_42.lib”
    • _HAS_ITERATOR_DEBUGGING 仅适用于调试版本。不过,关于_SECURE_SCL,您是否遇到过将启用它的库与禁用它的库混合使用的问题?
    • @James:啊,不知道_HAS...。至于你的第二个问题,我不知道。我在使用 Boost 的发布版本中禁用了它,因此它们匹配。
    【解决方案2】:

    在 Windows 上,获取 boost 二进制库的最简单方法是运行 installer from BoostPro consulting。请务必选择您的 Visual Studio 版本并在安装过程中选中正则表达式库复选框。

    【讨论】:

    • 如果他们没有随意做一些愚蠢的事情,比如制作一个你点击的 bat 文件,那么默认源安装会很容易,但不会完成整个工作。为什么程序员不能做出第一次就可以工作的工具,并且遵循最少惊奇的原则。 BoostPro 的安装程序很好,我只是在抱怨 boost 网站的 zip 文件下载。在我看来,他们应该把它们放下,然后把一个链接放到一个真正的安装上。当然,BoostPro 已经死了或死了,所以这个答案将不再是最新的。
    【解决方案3】:

    你安装了多线程调试版的 Boost 吗?如果没有,请这样做。否则请检查您的库路径(在项目首选项中),使其包含错误消息中提到的文件的路径。

    【讨论】:

      【解决方案4】:

      我不确定定义设置,但通过运行&lt;boostroot&gt;\bootstrap 批处理文件,然后按如下方式编辑&lt;boostroot&gt;\project-config.jam 文件,我能够使用MSVC 9.0 进行构建。换行:

      using mvsc
      

      到:

      using msvc : 9.0 : cl.exe
      

      然后运行.\b2 install,boost 头文件和库被构建并安装到c:\boost

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-02-22
        • 2011-06-14
        • 1970-01-01
        • 2017-11-04
        • 2012-10-14
        • 1970-01-01
        • 2013-05-15
        • 2018-04-07
        相关资源
        最近更新 更多