1

I have downloaded the boost library and want to include it in visual c++, but after copying in a piece of example code from the boost website, I get the error

"LNK1104 cannot open file 'libboost_regex-vc100-mt-gd-1_54'"

The file certainly exists. I'm guessing it was created when I ran the bootstrap command in the command prompt, which I followed from the guide https://www.youtube.com/watch?v=6trC5zVXzG0

The example file I use is as follows:

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

using namespace std;

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

I'm sorry but I know this kind of question has appeared several times on stack overflow, but I have tried most of the solutions I've seen and the error still exists.

Inside the solution explorer in visual c++ 2015, I write click on my proect and then click on properties, then under the VC++ directories tab, I've added the directory "C:\Program Files\Boost" into include directories, and the directory "C:\Program Files\Boost\stage\lib" into library directories. But the problem still exists. Similar questions on stack have asked to add the directory "C:\Program Files\Boost\stage\lib" to the Additional Include Directories under the general tab under the C/C++ tab, and to the Additional Include Directories under the General tab inside the Linker tab. But all these changes made no difference to the error. Another solution on stack said to add the directory "C:\Program Files\Boost\stage\lib" to the Additional dependencies under the input tab under the Linker tab, but when I did this the error changed to:

"LNK1104 cannot open file 'C:\Program Files\Boost\stage\lib.ob'"

I'm not sure if this is an improvement to the error or not

So after trying all these solutions which seemed to work for other people, I keep getting the same error. So does anyone know what could be the cause of the error.

user217339
  • 169
  • 1
  • 2
  • 11
  • I added in libboost_regex-vc100-mt-gd-1_54.lib; into the Additonal dependencies property in Configuration properties -> Linker -> Input. This seemed to change the error to 4 new errors, "LNK2038 Mismatched detection for '_MSC_VER':value '1600' doesn't match value '1900' in stdafx.obj" – user217339 Nov 22 '15 at 00:10
  • Try rebuilding the [library](http://stackoverflow.com/questions/31566807/how-to-build-boost-version-1-58-0-using-visual-studio-2015-enterprise). Visual c++ 2015 == v140, and you're linking with vc100 version. – Grigorii Chudnov Nov 29 '15 at 23:06

2 Answers2

0

You are getting a LNK error, which means it's likely that something is missing from your Linker properties. Make sure you've added both the boost folder and the boost\stage\lib folder to the Project Properties > configuration > Linker > "Additional Library Directories".

Also note that if you're using Visual Studio 2015, you should probably have generated the boost binaries using msvc-14.0, not msvc-10.0. Otherwise, your Platform Toolset property should be set to v100 (the default will be v140). You change this setting from Project Properties > configuration > General > "Platform Toolset", but you would need to have that version of visual studio installed.

Aciel
  • 95
  • 11
0

If Aciel's answer haven't solve your problem(because I saw you haven't accept that answer yet), I believe it is because you compile your boost lib to 32-bit, and you use them in a 64-bit program. If it's so, please try

bjam --toolset=msvc-14.0 --build-type=complete address-model=64

to rebuild your boost lib to 64-bit

calvin
  • 2,125
  • 2
  • 21
  • 38