C++ 链接器错误 LNK1104 与“libboost_filesystem-vc100-mt-s-1_49.lib”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9628527/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 13:05:41  来源:igfitidea点击:

Linker error LNK1104 with 'libboost_filesystem-vc100-mt-s-1_49.lib'

c++boost

提问by vizcayno

During the process of linking my program to the boost::filesystem module in release mode I get the next error:

在发布模式下将我的程序链接到 boost::filesystem 模块的过程中,我收到下一个错误:

error LNK1104: cannot open file 'libboost_filesystem-vc100-mt-s-1_49.lib'

错误 LNK1104:无法打开文件“libboost_filesystem-vc100-mt-s-1_49.lib”

However, in the boost\stage\lib directory I only have the next libraries referred to filesystem module:

但是,在 boost\stage\lib 目录中,我只有下一个引用文件系统模块的库:

libboost_filesystem-vc100-mt-1_49.lib

libboost_filesystem-vc100-mt-gd-1_49.lib

libboost_filesystem-vc100-mt-1_49.lib

libboost_filesystem-vc100-mt-gd-1_49.lib

My questions are:

我的问题是:

Why does the VC++ is asking for 'libboost_filesystem-vc100-mt-s-1_49.lib?

为什么 VC++ 要求'libboost_filesystem-vc100-mt-s-1_49.lib?

Which compiler/linking properties should I change to get the compiler to ask for libboost_filesystem-vc100-mt-1_49.lib?

我应该更改哪些编译器/链接属性以使编译器要求 libboost_filesystem-vc100-mt-1_49.lib?

UPDATE: My VC2010++ solution has 2 projects that include the previous boost library: x is a library and y (the main program) which invokes to x.

更新:我的 VC2010++ 解决方案有 2 个项目,其中包括以前的 boost 库:x 是一个库,y(主程序)调用 x。

  1. When I build x with Configuration type=Static library and RuntimeLibrary=Multi-threaded (/MT), it is ok.
  2. When I build y with Configuration type=Application (.exe) and RuntimeLibrary=Multi-threaded (/MT), it issues the error I indicated, if I change to Configuration type=Static library it builds ok, but my main program has .lib extension and not the expected .exe.
  1. 当我使用 Configuration type=Static library 和 RuntimeLibrary=Multi-threaded (/MT) 构建 x 时,就可以了。
  2. 当我使用 Configuration type=Application (.exe) 和 RuntimeLibrary=Multi-threaded (/MT) 构建 y 时,它会发出我指出的错误,如果我更改为 Configuration type=Static 库,它构建正常,但我的主程序有 . lib 扩展名而不是预期的 .exe。

采纳答案by secmask

You are using /MT or /MTd option in C/C++/Code Generation/Runtime Librarywhich require static library, boost default build with shared library output. You can switch Runtime Libraryto /MD or /MDd. An other option is recompile boost with static library output and you'll get 'libboost_filesystem-vc100-mt-s-1_49.lib'..

您正在使用 /MT 或 /MTd 选项,C/C++/Code Generation/Runtime Library其中需要静态库,使用共享库输出提升默认构建。您可以切换Runtime Library到 /MD 或 /MDd。另一个选项是使用静态库输出重新编译 boost,您将获得“libboost_filesystem-vc100-mt-s-1_49.lib”..

回答by kalenwatermeyer

I had a similar problem with a recent project (inherited from a long legacy).

我在最近的一个项目中遇到了类似的问题(继承自一个长期的遗产)。

Here is a "poor man's" solution to this issue:

这是针对此问题的“穷人”解决方案:

Rebuild the boost libraries with allvariants, to be sure that you have the correct variant for your needs.

使用所有变体重新构建boost 库,以确保您拥有满足您需求的正确变体。

Run:

跑:

.\b2 --build-type=complete

Note that the boost build time will obviously be longer with this option.

请注意,使用此选项,boost 构建时间显然会更长。

This is not an elegant solution, but I didn't have time to mess about figuring out which exact option I needed for my project, so I just built them all.

这不是一个优雅的解决方案,但我没有时间去弄清楚我的项目需要哪个确切的选项,所以我只是构建了它们。

回答by huoyao

You can paste the following characters into you control console (win+r----cmd , then go to boost src directory , find the bjam.exe) ps:double click the bootstrap.bat can get bjam.exe

您可以将以下字符粘贴到您的控制台中(win+r----cmd,然后进入boost src目录,找到bjam.exe) ps:双击bootstrap.bat可以得到bjam.exe

bjam --toolset=msvc-1.0 --stagedir=./lib_x64 --builddir=./ address-model=32 link=static variant=release runtime-link=static threading=multi stage debug releasde


libboost_filesystem-vc100-mt-s-1_49.lib


"link=static" correspond to -s-
"threading=multi" correspond to -mt-
"runtime-link=static" correspond to lib prefix
"variant=release" make sure libboost_filesystem-vc100-mt-s-1_49.lib don't contain -gd-

回答by akhisp

The boost libraries that you have in your boost\stage\lib directoryare linking dynamically to the standard C++ libraries. See the following post:

您拥有的 boost 库boost\stage\lib directory动态链接到标准 C++ 库。请参阅以下帖子:

boost lib build configuraton variations

boost lib 构建配置变体

Your code is linking statically to the standard C++ libraries, hence a mismatch. Try linking your code dynamically to the standard libraries. (Project Settings->General->Configuration Type)

您的代码静态链接到标准 C++ 库,因此不匹配。尝试将您的代码动态链接到标准库。(项目设置->通用->配置类型)

回答by Warm Guest

run below command to rebuild boost in static in VS2013 x86 Native Tools Command Prompt.

运行以下命令以在 VS2013 x86 Native Tools Command Prompt 中以静态方式重建 boost。

b2 -link=static

Add your linker library paths in your project link path in VS. Then, rebuild your project, error gone.

在 VS 的项目链接路径中添加链接器库路径。然后,重建您的项目,错误消失了。