简体   繁体   English

如何确保 Visual Studio 2015 中 C++ 的机器之间的构建环境一致?

[英]How do I ensure a consistent build environment across machines in for C++ in Visual Studio 2015?

I have some C++ code in visual studio 2015 that compiles and works fine on my machine, but not on my team mate's.我在 Visual Studio 2015 中有一些 C++ 代码可以在我的机器上编译并正常工作,但在我的队友的机器上却不行。

We have the exact same code base, and the exact same versions of all the same libraries, but on his machine, Visual Studio fails to properly resolve some macros of templates correctly, while mine works just fine.我们有完全相同的代码库,以及所有相同库的完全相同的版本,但在他的机器上,Visual Studio 无法正确解析模板的某些宏,而我的工作正常。

I'm trying to recreate his build environment so I can reproduce the issue.我正在尝试重新创建他的构建环境,以便重现该问题。 We're both using visual studio 15 update 3 Version 14.0.25431.01, but the Visual C++ 2015 versions are different, but I can't find a way to specify the version I'd like visual studio to use.我们都使用 Visual Studio 15 更新 3 版本 14.0.25431.01,但 Visual C++ 2015 版本不同,但我找不到指定我希望 Visual Studio 使用的版本的方法。

How do I do so?我该怎么做? And in general, how do I ensure our build environments are consistent in visual studio?一般来说,我如何确保我们的构建环境在 Visual Studio 中是一致的?


EDIT: To pull in some further info from the comments on what we've done so far:编辑:从我们迄今为止所做的评论中获取更多信息:

  • We're both using the exact same version of visual studio 2015 (update 3 Version 14.0.25431.01)我们都使用完全相同版本的 Visual Studio 2015(更新 3 版本 14.0.25431.01)
  • Ensuring our libraries are relative to the solution directory and are downloaded along with the project repo so there's no wrong paths确保我们的库与解决方案目录相关,并与项目 repo 一起下载,因此没有错误的路径
  • Included the project files and solution in the repo and ensured they have the same在 repo 中包含项目文件和解决方案,并确保它们具有相同的
    • Target Platform Version (Windows SDK version): Windows 8.1目标平台版本(Windows SDK 版本):Windows 8.1
    • Platform toolset: Visual Studio 2015 (v140)平台工具集:Visual Studio 2015 (v140)

EDIT: As @Marek R mentioned, I should include the exact error I was having: I'm trying to do some signal processing with the Eigen library.编辑:正如@Marek R 提到的,我应该包括我遇到的确切错误:我正在尝试使用 Eigen 库进行一些信号处理。

The exact line it crashes on tries to initialise an array as so:它崩溃的确切行尝试如下初始化数组:

Eigen::ArrayX<int> foo(size_of_the_array) then use that array as so: Eigen::ArrayX<int> foo(size_of_the_array)然后使用该数组:

foo(index) = bar

Eigen uses a macro over template using statements to redefine this type as to: Eigen::Array<int,-1,1> Eigen 在模板上使用宏,使用语句将这种类型重新定义为: Eigen::Array<int,-1,1>

This works as expected on my machine, but when trying to compile on his, it fails这在我的机器上按预期工作,但是当试图在他的机器上编译时,它失败了

3>HighRes.cpp(187): error C2514: 'Eigen::Array<int,-1,1,,-1,1>': class has no constructors
3>  c:\WORKING_DIR\sigproc_vs2015\eigen\eigen\src/Core/Array.h(46): note: see declaration of 'Eigen::Array<int,-1,1,,-1,1>' 3>HighRes.cpp(188): error C2039: 'size': is not a member of 'Eigen::Array<int,-1,1,,-1,1>'

3>  c:\WORKING_DIR\sigproc_vs2015\eigen\eigen\src/Core/Array.h(46): note: see declaration of 'Eigen::Array<int,-1,1,,-1,1>' 3>HighRes.cpp(188): error C2039: '__this': is not a member of 'Eigen::Array<int,-1,1,,-1,1>'

3>  c:\WORKING_DIR\sigproc_vs2015\eigen\eigen\src/Core/Array.h(46): note: see declaration of 'Eigen::Array<int,-1,1,,-1,1>' 3>HighRes.cpp(189): error C2064: term does not evaluate to a function taking 1 arguments

What's even more strange is other sections of the code have similar calls to this macro, but with other types eg: Eigen::ArrayX<bool> baz(some_other_size);更奇怪的是代码的其他部分对这个宏有类似的调用,但是有其他类型,例如: Eigen::ArrayX<bool> baz(some_other_size); and his build doesn't complain about those.而且他的身材并没有抱怨这些。 I'm trying to reproduce this behavior on mine.我试图在我的身上重现这种行为。


UPDATE: I've had a chance to play with his machine a little more, and I notice a couple of things:更新:我有机会玩他的机器多一点,我注意到几件事:

1: His machine is fine instantiating Eigen::ArrayX<T> anywhere else, apart from the specific section of the code the that failed to build earlier 1:他的机器可以很好地在其他任何地方实例化Eigen::ArrayX<T> ,除了之前未能构建的特定代码部分

2: The only thing special about that specific section is it's is inside a closure 2:该特定部分的唯一特别之处在于它位于闭包内

auto process_in_parallel = [state](int dimension){ 
    // Other code...
    Eigen::ArrayX<int> foo(size_of_the_array);

3: Eigen uses nested macros to define template using statements which define the ArrayX class. 3:Eigen 使用嵌套宏定义模板,使用定义 ArrayX class 的语句。

I've actually had a lot of trouble getting visual studio 15 to work with template using statements and nested template classes;实际上,我在让 Visual Studio 15 使用语句和嵌套模板类使用模板时遇到了很多麻烦; the compiler would often crash and just ask me to simplify my code around a given line.编译器经常会崩溃,只是要求我在给定的行周围简化我的代码。 I'm happy to just work around this by changing the definition to Eigen::ArrayXi ;我很高兴通过将定义更改为Eigen::ArrayXi来解决这个问题; a non-template type alias.非模板类型别名。 This compiles just fine, and the build passes all tests.这编译得很好,并且构建通过了所有测试。

You will need to synchronize the projects and solutions across PCs, as well as the code base.您将需要跨 PC 以及代码库同步项目和解决方案。

If you do this, then you can explicitly select which build tools to use for any project in that project's properties:如果您这样做,那么您可以显式 select 构建用于该项目属性中任何项目的工具:

Configuration Properties -> General -> Platform Toolset配置属性 -> 常规 -> 平台工具集

Be sure to have the same one selected on different PCs (this will have to be a toolset that both PCs have installed).确保在不同的 PC 上选择相同的工具(这必须是两台 PC 都安装的工具集)。

EDIT: You should probably also ensure that the selected "Windows SDK Version" is the same for all projects across the two PCs.编辑:您可能还应该确保选择的“Windows SDK 版本”对于两台 PC 上的所有项目都是相同的。 This may not evaluate to the same thing if 'latest version' is selected.如果选择了“最新版本”,这可能不会评估为相同的东西。 (And you may also need to install the SDK that 'works' for you on your colleague's PC.) (而且您可能还需要在您同事的 PC 上安装适合您的 SDK。)

the Visual C++ 2015 versions are different Visual C++ 2015 版本不同

The easiest way to fix this is to update Visual Studio to the latest version for both of you.解决此问题的最简单方法是将 Visual Studio 更新到你们俩的最新版本。 It will also update all installed components, including C++ toolset.它还将更新所有已安装的组件,包括 C++ 工具集。

Another thing which might differ is components of Windows SDK installed and a set of system libraries.另一个可能不同的是 Windows SDK 的组件和一组系统库。 Make sure you are using the same versions of Windows (use winver command).确保您使用的是相同版本的 Windows(使用winver命令)。 An error message would help to diagnose the problem.错误消息将有助于诊断问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使Visual Studio 2015 C ++项目与Visual Studio 2010兼容? - How do I make a Visual Studio 2015 C++ project compatible with Visual Studio 2010? 如何在 Visual Studio 2015 中使用 mongoose 构建 C++ 项目 - How to build a C++ project using mongoose in Visual Studio 2015 如何在Visual Studio 2015中构建具有循环依赖项的C ++项目? - How can I build a C++ project in Visual Studio 2015 with circular dependencies? 如何在Visual Studio 2015中调试现有的C ++源代码? - How do I debug existing C++ source code in Visual Studio 2015? 如何在 Visual Studio 2015 中使用 c++ 语言? - How can I work with c++ language in visual studio 2015? 如何设置此Visual Studio(2015)自定义构建步骤(工具?)。 基本上我想要一个预处理器步骤,用于修改头文件(C ++) - How do I set up this visual studio (2015) custom build step (tool?). Basically I want a pre-preprocessor step that modifies header files (c++) Visual Studio 2015:如何建立针对Visual C ++ v120的ATL专案 - Visual Studio 2015: how to build ATL projects targeting Visual C++ v120 Visual Studio 2015社区C ++构建失败:任务已取消 - Visual Studio 2015 Community C++ Build Failure: A task was cancelled Visual Studio 2015:为Android生成C ++ 11库 - Visual Studio 2015: Build C++ 11 library for Android 在Visual Studio 2015 c ++中构建android native app - build android native app in Visual Studio 2015 c++
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM