C++ / Boost Filesystem - mismatch detected for 

2020-03-01 17:15发布

问题:

I'm new to C++ and Boost. I'm doing a small simple program to trying to learn the Boost Filesystem library. I have followed the directions to build the Boost libs. And now when I try to compile this simple code I get 6 of these errors.

Error   5   error LNK2038: mismatch detected for '_MSC_VER': value '1700' doesn't match value '1600' in App.obj C:\SOURCE\ConsoleApp2\ConsoleApp2\libboost_filesystem-vc110-mt-gd-1_51.lib(codecvt_error_category.obj)  ConsoleApp2  
Error   1   error LNK2038: mismatch detected for '_MSC_VER': value '1700' doesn't match value '1600' in App.obj C:\SOURCE\ConsoleApp2\ConsoleApp2\libboost_filesystem-vc110-mt-gd-1_51.lib(operations.obj)  ConsoleApp2  
Error   2   error LNK2038: mismatch detected for '_MSC_VER': value '1700' doesn't match value '1600' in App.obj C:\SOURCE\ConsoleApp2\ConsoleApp2\libboost_filesystem-vc110-mt-gd-1_51.lib(path.obj)    ConsoleApp2  
Error   3   error LNK2038: mismatch detected for '_MSC_VER': value '1700' doesn't match value '1600' in App.obj C:\SOURCE\ConsoleApp2\ConsoleApp2\libboost_filesystem-vc110-mt-gd-1_51.lib(path_traits.obj) ConsoleApp2  
Error   4   error LNK2038: mismatch detected for '_MSC_VER': value '1700' doesn't match value '1600' in App.obj C:\SOURCE\ConsoleApp2\ConsoleApp2\libboost_filesystem-vc110-mt-gd-1_51.lib(windows_file_codecvt.obj)    ConsoleApp2  
Error   6   error LNK1104: cannot open file 'libboost_filesystem-vc100-mt-gd-1_51.lib'  C:\SOURCE\ConsoleApp2\ConsoleApp2\LINK  ConsoleApp2  

My code in App.cpp in my ConsoleApp2 project

#include <iostream>
#include <boost/filesystem.hpp>

using namespace std;
using namespace boost::filesystem;

int main(void) 
{
    path p = "C:\\TestFiles";
    cout << is_directory(p);

    return 0;
}

I'm trying to compile the app with Visual Studio 2010. Some of the info I have found online were related to VS 2012. This I don't think applies to me. I'd like to try to solve the 5 mismatch errors and the final link error. I'm hoping the last error is related to the 5 before it.

回答1:

libboost_filesystem-vc110-mt-gd-1_51.lib is a library that has been built with VS 2012 (Also known as VC 11.0), as indicated by the vc110 in the naming convention. This library will not link properly with objects built with VS 2010 (also known as VC 10.0).

If you want to build your program with VS 2010, you'll need to get or build boost libraries for VS 2010.



回答2:

Open the *.vcxproj file with a text editor.

Find and delete the <_ProjectFileVersion> element, and then save the file.

Example,

</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
  <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>

  <_ProjectFileVersion>11.0.30319.1</_ProjectFileVersion> <--- Delete this element

</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">

And rebuild the solution again. You will see the project compiling successfully.



回答3:

I was trying to compile the Teamcenter ITK C++ code and got the same error message:

error LNK2038: mismatch detected for '_MSC_VER': value '1700' doesn't match value '1600' in itk_main.obj

The workaround I did was searching for msvcprt.lib sitting somewhere in c: (used everything.exe to search, which can be found on voidtools.com)

Opened that file in NP++ or text editor search for keyword _MSC_VER and changed the value /FAILIFMISMATCH:"_MSC_VER=1700" to /FAILIFMISMATCH:"_MSC_VER=1600"

And yes, I was able to compile.



回答4:

solution mentioned by vignesh naidu worked for me.

but not exactly msvcprt.lib

look for the .lib file in the error msg.

In my case, there was somefile.lib , i searched in the file explorer which gave two similar files in folder

1)Release 2)Debug

Opened somefile.lib in debug folder, opened in NP++ , found and replaced for ex: 1700 with 1900 (VS 2015) in my case

recompiled, viola error gone.

For brief explanation about why,how there are several technical reasons given by other users.

PS: i was compiling code built in VS 2012 in VS2015 and 1700 is compiler version for VS 2012 , 1900 for VS 2015