C++/Boost 文件系统 - 检测到“_MSC_VER”不匹配:值“1700”与值“1600”不匹配

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12398809/
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 16:14:57  来源:igfitidea点击:

C++ / Boost Filesystem - mismatch detected for '_MSC_VER': value '1700' doesn't match value '1600'

c++visual-studioboostboost-filesystem

提问by BuddyJoe

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.

我是 C++ 和 Boost 的新手。我正在做一个简单的小程序来尝试学习 Boost 文件系统库。我已按照说明构建 Boost 库。现在当我尝试编译这个简单的代码时,我得到了 6 个这样的错误。

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.cppin my ConsoleApp2 project

App.cpp我的 ConsoleApp2 项目中的代码

#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.

我正在尝试使用 Visual Studio 2010 编译应用程序。我在网上找到的一些信息与 VS 2012 相关。我认为这不适用于我。我想尝试解决 5 个不匹配错误和最终链接错误。我希望最后一个错误与它之前的 5 个错误有关。

回答by Michael Burr

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

libboost_filesystem-vc110-mt-gd-1_51.lib是使用 VS 2012(也称为 VC 11.0)构建的库,如vc110命名约定中所示。此库将无法与使用 VS 2010(也称为 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.

如果你想用 VS 2010 构建你的程序,你需要为 VS 2010 获取或构建 boost 库。

回答by Kanchari Srikanth

Open the *.vcxprojfile with a text editor.

*.vcxproj使用文本编辑器打开文件。

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

查找并删除<_ProjectFileVersion>元素,然后保存文件。

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.

并再次重建解决方案。您将看到项目编译成功。

回答by vignesh naidu

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

我试图编译 Teamcenter ITK C++ 代码并收到相同的错误消息:

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

错误 LNK2038:检测到“_MSC_VER”不匹配:值“1700”与 itk_main.obj 中的值“1600”不匹配

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)

我所做的解决方法是搜索位于 c 中某处的 msvcprt.lib(使用everything.exe 进行搜索,可以在 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"

在 NP++ 或文本编辑器中打开该文件搜索关键字 _MSC_VER 并将值 /FAILIFMISMATCH:"_MSC_VER=1700" 更改为 /FAILIFMISMATCH:"_MSC_VER=1600"

And yes, I was able to compile.

是的,我能够编译。

回答by roshan_nazareth

solution mentioned by vignesh naidu worked for me.

vignesh naidu 提到的解决方案对我有用。

but not exactly msvcprt.lib

但不完全是 msvcprt.lib

look for the .lib file in the error msg.

在错误消息中查找 .lib 文件。

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

就我而言,有 somefile.lib ,我在文件资源管理器中搜索,在文件夹中提供了两个类似的文件

1)Release 2)Debug

1)发布 2)调试

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

在调试文件夹中打开 somefile.lib,在 NP++ 中打开,找到并替换为例如:1700 与 1900(VS 2015)在我的情况下

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

PS:我在 VS2015 中编译了 VS 2012 中的代码,1700 是 VS 2012 的编译器版本,VS 2015 的编译器版本是 1900