【问题标题】:linking boost in 64-bit program VS2015在 64 位程序 VS2015 中链接 boost
【发布时间】:2016-09-24 09:11:44
【问题描述】:

我正在将一个大型 boost 密集型程序升级到 VS2015 和 boost 1.61。该程序是64位程序-x64

Boost 似乎在 64 位模式下寻找错误的库(或者更有可能我做了一些愚蠢的事情)。我相信我已经为 VS2015 平台构建了正确的 boost 库。

我尝试在 WIN32 模式下从头开始制作一个微小的增强功能,这需要静态链接。这工作正常......

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

void test()
{
 std::string line;
 boost::regex pat("^Subject: (Re: |Aw: )*(.*)");
  while (std::cin)
  {
    std::getline(std::cin, line);
    boost::smatch matches;
    if (boost::regex_match(line, matches, pat))
        std::cout << matches[2] << std::endl;
  }
}

但是当我想在 x64 中编译时,boost 会抱怨。是的,我已经为两个平台正确设置了#include 和链接路径。图书馆不在那里。

1>链接:致命错误 LNK1104:无法打开文件“libboost_regex-vc140-mt-gd-1_61.lib”

libboost_regex-vc140-mt-1_61.lib

【问题讨论】:

  • 名字的-gd部分表示调试,尝试在release模式下编译你的程序或者在debug模式下编译boost库

标签: c++ boost visual-studio-2015


【解决方案1】:
  1. 检查您是否在 64 位上构建了 boost
  2. 检查是否已将 boost 库文件夹添加到 che Visual Studio 项目(属性->链接器->常规->附加库文件夹)
  3. 检查您是否正在构建 64 位解决方案
  4. 如果您没有使用自动链接,请检查您是否在项目中添加了库依赖项(属性->链接器->输入->附加依赖项)

【讨论】:

  • 我应该为 x64 构建 libboost_regex-vc140-mt-1_61.lib 和 libboost_regex-vc140-mt-gd-1_61.lib C:\boost\boost_1_61_0>b2 -j8 toolset=msvc- 14.0 address-model=64 architecture=x86 link=static threading=multi runtime-link=shared --build-type=minimal stage --stagedir=stage/x64 。我现在尝试从头开始制作控制台应用程序。这行得通!在 64 位模式下。它在这里寻找 libboost_regex-vc140-mt-1_61.lib。但是 Windows 应用程序会查找不存在的东西agedir=stage/x64
  • 如何在答案中换行?
【解决方案2】:

您需要构建编译器要求的正确库集。您应该咨询library naming chart 以获取要在构建时使用的构建参数(即属性)。在您的情况下,它正在寻找标记为“lib--mt-gd-1_61.lib”的库。阅读图表表明您需要构建:

link=static threading=multi runtime-debugging=on variant=debug

【讨论】:

    猜你喜欢
    • 2020-07-08
    • 2010-12-28
    • 2019-07-06
    • 2016-06-01
    • 1970-01-01
    • 2012-01-02
    • 2020-02-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多