5

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.

Hexx i.m
  • 91
  • 5
  • where are the error messages in you question? `fails to properly resolve some macros of templates correctly` is not an error description. – Marek R Oct 14 '19 at 13:27
  • The first thing to do to ensure that path are properly configured might be to try it in a completely different directory on your computer (if you have a single computer). And if you have access on a second computer or can have automated builds, it is even better. – Phil1970 Oct 14 '19 at 13:59
  • @Phil1970 Yeah the include and link paths are all relative to the solution_dir, and all the libraries are cloned as submodules in the solution_dir. We use .props files which are part of the project repo to point to these. We tried re-cloning in a new location anyway, but the issue persists – Hexx i.m Oct 14 '19 at 14:07
  • 1
    You could compile that one file with [`/showIncludes`](https://learn.microsoft.com/en-us/cpp/build/reference/showincludes-list-include-files?view=vs-2019) and hash all the files listed or just straight up save the preprocessor output and diff that – PeterT Oct 14 '19 at 14:11
  • 1
    This is clearly dependency management issue. Something like different versions of `Eigen` installed on both machines. Incorrect configuration of `Eigen` or absolute paths used in project. – Marek R Oct 14 '19 at 14:23
  • @MarekR I thought so as well initially, but we use a specific commit on eigen as a git submodule in the project repo, and the include directories are relative to the solution_dir, and point to the folder it clones into. I checked, and we've both cloned the same commit hash with no changes – Hexx i.m Oct 14 '19 at 14:31
  • @Hexxi.m there is one strange thing in this build log: `'Eigen::Array'` Note 4th template parameter is empty! AFAIK you can't have empty template argument. This must be result of macro resolution. You have to track how macros are resolved to be able spot difference between those two machines. – Marek R Oct 14 '19 at 15:06
  • Did you try universal solution: fresh build (rebuild), checkout code in new different directory? Sometimes MSVC caches something incorrectly producing strange results. – Marek R Oct 14 '19 at 15:09
  • yeah, I was really confused about that. The macro only specifies the first 3 template arguments. The rest are supposed to use the default values, and that middle one should be zero, but for some reason, his machine isn't resolving that, and mine is – Hexx i.m Oct 14 '19 at 18:01
  • If VC++ versions differ, one of you needs an update. Run VS installer and update. If using precompiled headers, flush them. Also delete the .vs folder. – rustyx Oct 15 '19 at 07:47
  • Have you correctly included the .h and lib files of the Eigen library? [Compiler Error C2514](https://learn.microsoft.com/en-us/cpp/error-messages/compiler-errors-2/compiler-error-c2514?redirectedfrom=MSDN&view=vs-2019).[About using eigen library](https://social.msdn.microsoft.com/Forums/vstudio/en-US/fbe50f91-e0a6-4a28-a4dc-6473765f8239/about-using-eigen-library?forum=vcgeneral) – Jeaninez - MSFT Oct 15 '19 at 09:18
  • @Jeaninez-MSFT yeah, i have. I should mention, we extensively use eigen through this project, and every other use works just fine except for this one line – Hexx i.m Oct 15 '19 at 10:41
  • Only the vc++ version is different, all other products are the same. I can only recommend that you update the vs version. – Jeaninez - MSFT Oct 16 '19 at 06:12

2 Answers2

0

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

Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
  • We are using the same projects and solutions files, and in both, it is set to use "Visual Studio 2015 (v140)" as the platform toolset – Hexx i.m Oct 14 '19 at 13:32
  • I don't see an option for "Windows SDK Version". Do you mean "Target Platform Version"? – Hexx i.m Oct 14 '19 at 13:56
  • Yes, they both target windows 8.1 – Hexx i.m Oct 14 '19 at 14:02
  • @Hexxi.m Then I'm confused! If you have the same VS updates, you should have the same C++ compiler - I think? Maybe the versions of Eigen are different?? – Adrian Mole Oct 14 '19 at 14:38
  • when i say the versions are different, i mean when I check `help > About Microsoft Visual Studio` and look at the list of installed products, the numbers next to Visual C++ 2015 are different, but all other products are the same. I presume those are the version numbers? – Hexx i.m Oct 14 '19 at 18:03
0

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.

Mikhail
  • 20,685
  • 7
  • 70
  • 146