37

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

error LNK1104: cannot open file '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:

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?

Which compiler/linking properties should I change to get the compiler to ask for 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.

  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.
Community
  • 1
  • 1
vizcayno
  • 1,223
  • 3
  • 16
  • 24
  • 1
    WRT your update, when you build a static library the linker isn't invoked, so any link errors disappear. You will get the same link errors when you try to build an .exe or .dll that uses your static library. – JoeG Mar 09 '12 at 04:35

5 Answers5

31

You are using /MT or /MTd option in C/C++/Code Generation/Runtime Library which require static library, boost default build with shared library output. You can switch Runtime Library to /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'..

secmask
  • 7,649
  • 5
  • 35
  • 52
  • 1
    @peachykeen: it affects boost library, I've already use this static way. Boost static library could be built as discuss here http://stackoverflow.com/questions/494629/building-boost-for-static-linking-mingw – secmask Mar 09 '12 at 04:29
  • 1
    I built the boost library using the simplified build from source, i.e. bootstrap and then .\bjam, assuming it is sufficient. I updated my question, may be I am doing something wrong. Thanks!! – vizcayno Mar 09 '12 at 04:39
  • @user255053: see the link in secmask's comment above. You need to use link=static and runtime-link=static – ehambright Jan 16 '13 at 21:27
  • 1
    I am trying to link debug library to my project and the same /MTd option doesn't fix the problem. It fixed in in release build though. Any idea why I still get the error in debug build? – zar Nov 12 '13 at 18:07
22

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 all variants, to be sure that you have the correct variant for your needs.

Run:

.\b2 --build-type=complete

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

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.

kalenwatermeyer
  • 741
  • 12
  • 24
  • Does this require you to be in some particular directory, and/or to have certain PATH defined, or anything like that? – Dronz Mar 17 '19 at 07:05
  • I get: "'.\b2' is not recognized as an internal or external command,operable program or batch file." when I try to run ".\b2 --build-type=complete" using the VS 2017 x86 Native Tools Command Prompt from my /boost directory. – Dronz Mar 18 '19 at 21:42
6

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

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-
huoyao
  • 131
  • 1
  • 5
2

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

b2 -link=static

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

Warm Guest
  • 21
  • 1
2

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

boost lib build configuraton variations

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)

Community
  • 1
  • 1
akhisp
  • 675
  • 3
  • 5
  • Did you read the link I posted? Do you know what the "-s" stands for in the boost lib file name? – akhisp Mar 09 '12 at 04:21
  • +1; good answer, I've added a bit to hopefully avoid any further confusion – JoeG Mar 09 '12 at 04:30
  • Hi, I updated my question in the attempt to give you more elements to help me. Thanks for your comprehension. – vizcayno Mar 09 '12 at 04:44