简体   繁体   中英

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.

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.

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.

How do I do so? And in general, how do I ensure our build environments are consistent in 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)
  • Ensuring our libraries are relative to the solution directory and are downloaded along with the project repo so there's no wrong paths
  • Included the project files and solution in the repo and ensured they have the same
    • Target Platform Version (Windows SDK version): Windows 8.1
    • Platform toolset: 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.

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:

foo(index) = bar

Eigen uses a macro over template using statements to redefine this type as to: 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); 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

2: The only thing special about that specific section is it's is inside a closure

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.

I've actually had a lot of trouble getting visual studio 15 to work with template using statements and nested template classes; 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 ; 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.

If you do this, then you can explicitly select which build tools to use for any project in that project's properties:

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

EDIT: You should probably also ensure that the selected "Windows SDK Version" is the same for all projects across the two PCs. 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.)

the Visual C++ 2015 versions are different

The easiest way to fix this is to update Visual Studio to the latest version for both of you. It will also update all installed components, including C++ toolset.

Another thing which might differ is components of Windows SDK installed and a set of system libraries. Make sure you are using the same versions of Windows (use winver command). An error message would help to diagnose the problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM