Fail to build on MSVC 2017

Issue #417 resolved
José Luis Blanco-Claraco created an issue

Hi guys. A terror story inside.

Issue #359 seems to be there despite the upgrade to Eigen 3.3.7 (error log copied below).

The offending lines are lines 44-45 of gtsam/base/Vector.h:

static const Eigen::MatrixBase<Vector2>::ConstantReturnType Z_2x1 = Vector2::Zero();
static const Eigen::MatrixBase<Vector3>::ConstantReturnType Z_3x1 = Vector3::Zero();

but in fact, if those are commented out (or replaced by #define ... as I did in a moment of despair), the problem shows up anywhere else where a Vector2 is instantiated.

After some experimentation I discovered the real cause of the problem: it's related to building SHARED libraries with MSVC. The compiler tries to generate the code for all methods, no matter whether they are actually invoked or not, so it ends up trying to instantiate w() from Eigen::Matrix of size 2 or 3, which has the static assert.

So frustrating...

Will try to update to the latest MSVC 2017 (right now I have 15.9.4) and cross fingers they MS guys already solved the problem, but it doesn't seem likely to me.

This error is preventing the compilation of gtsam at all in MSVC, as far as I know...

1>Cal3_S2Stereo.cpp
1>d:\code\gtsam-fork-jlblanco\gtsam\3rdparty\eigen\eigen\src\core\densecoeffsbase.h(216): error C2338: OUT_OF_RANGE_ACCESS
1>d:\code\gtsam-fork-jlblanco\gtsam\3rdparty\eigen\eigen\src\core\densecoeffsbase.h(215): note: while compiling class template member function 'const double &Eigen::DenseCoeffsBase<Derived,0>::w(void) const'
1>        with
1>        [
1>            Derived=gtsam::Vector2
1>        ]
1>d:\code\gtsam-fork-jlblanco\gtsam\3rdparty\eigen\eigen\src\core\densecoeffsbase.h(301): note: see reference to class template instantiation 'Eigen::DenseCoeffsBase<Derived,0>' being compiled
1>        with
1>        [
1>            Derived=gtsam::Vector2
1>        ]
1>d:\code\gtsam-fork-jlblanco\gtsam\3rdparty\eigen\eigen\src\core\densecoeffsbase.h(553): note: see reference to class template instantiation 'Eigen::DenseCoeffsBase<Derived,1>' being compiled
1>        with
1>        [
1>            Derived=gtsam::Vector2
1>        ]
1>d:\code\gtsam-fork-jlblanco\gtsam\3rdparty\eigen\eigen\src\core\densebase.h(47): note: see reference to class template instantiation 'Eigen::DenseCoeffsBase<Derived,3>' being compiled
1>        with
1>        [
1>            Derived=gtsam::Vector2
1>        ]
1>d:\code\gtsam-fork-jlblanco\gtsam\3rdparty\eigen\eigen\src\core\matrixbase.h(50): note: see reference to class template instantiation 'Eigen::DenseBase<Derived>' being compiled
1>        with
1>        [
1>            Derived=gtsam::Vector2
1>        ]
1>d:\code\gtsam-fork-jlblanco\gtsam\base\vector.h(44): note: see reference to class template instantiation 'Eigen::MatrixBase<gtsam::Vector2>' being compiled
1>Done building project "gtsam.vcxproj" -- FAILED.

Comments (11)

  1. Frank Dellaert

    Terror, indeed. But I do compile regularly on MSVC, with default cmake configuration, so what gives? Forget whether default is static or shared.

  2. José Luis Blanco-Claraco reporter

    Hmm... interesting. I retried from an empty cmake cache and (today's) latest MSVC compiler and it still fails with the same error, unless BUILD_SHARED_LIBS is set to OFF. Things seem to work when BUILD_SHARED_LIBS=OFF only...

    Could you please check what's the value of BUILD_SHARED_LIBS in your build? Just to 100% sure the problem is reproducible (as it should?!)... thanks!

  3. Frank Dellaert

    So, BUILD_SHARED_LIBS is ON for me. Will do re-build now after git pull to make sure, but it worked last time I tried. I do get a warning, possibly unrelated:

    CMake Warning (dev) in gtsam/CMakeLists.txt:
      Policy CMP0022 is not set: INTERFACE_LINK_LIBRARIES defines the link
      interface.  Run "cmake --help-policy CMP0022" for policy details.  Use the
      cmake_policy command to set the policy and suppress this warning.
    
      Target "gtsam" has an INTERFACE_LINK_LIBRARIES property which differs from
      its LINK_INTERFACE_LIBRARIES_DEBUG properties.
    
      INTERFACE_LINK_LIBRARIES:
    
        $<$<NOT:$<CONFIG:DEBUG>>:C:/Program Files/lib/libboost_serialization-vc141-mt-x32-1_67.lib>;$<$<CONFIG:DEBUG>:C:/Program Files/lib/libboost_serialization-vc141-mt-gd-x32-1_67.lib>;$<$<NOT:$<CONFIG:DEBUG>>:C:/Program Files/lib/libboost_system-vc141-mt-x32-1_67.lib>;$<$<CONFIG:DEBUG>:C:/Program Files/lib/libboost_system-vc141-mt-gd-x32-1_67.lib>;$<$<NOT:$<CONFIG:DEBUG>>:C:/Program Files/lib/libboost_filesystem-vc141-mt-x32-1_67.lib>;$<$<CONFIG:DEBUG>:C:/Program Files/lib/libboost_filesystem-vc141-mt-gd-x32-1_67.lib>;$<$<NOT:$<CONFIG:DEBUG>>:C:/Program Files/lib/libboost_thread-vc141-mt-x32-1_67.lib>;$<$<CONFIG:DEBUG>:C:/Program Files/lib/libboost_thread-vc141-mt-gd-x32-1_67.lib>;$<$<NOT:$<CONFIG:DEBUG>>:C:/Program Files/lib/libboost_date_time-vc141-mt-x32-1_67.lib>;$<$<CONFIG:DEBUG>:C:/Program Files/lib/libboost_date_time-vc141-mt-gd-x32-1_67.lib>;$<$<NOT:$<CONFIG:DEBUG>>:C:/Program Files/lib/libboost_regex-vc141-mt-x32-1_67.lib>;$<$<CONFIG:DEBUG>:C:/Program Files/lib/libboost_regex-vc141-mt-gd-x32-1_67.lib>;$<$<NOT:$<CONFIG:DEBUG>>:C:/Program Files/lib/libboost_timer-vc141-mt-x32-1_67.lib>;$<$<CONFIG:DEBUG>:C:/Program Files/lib/libboost_timer-vc141-mt-gd-x32-1_67.lib>;$<$<NOT:$<CONFIG:DEBUG>>:C:/Program Files/lib/libboost_chrono-vc141-mt-x32-1_67.lib>;$<$<CONFIG:DEBUG>:C:/Program Files/lib/libboost_chrono-vc141-mt-gd-x32-1_67.lib>;metis
    
      LINK_INTERFACE_LIBRARIES_DEBUG:
    
        C:/Program Files/lib/libboost_serialization-vc141-mt-gd-x32-1_67.lib;C:/Program Files/lib/libboost_system-vc141-mt-gd-x32-1_67.lib;C:/Program Files/lib/libboost_filesystem-vc141-mt-gd-x32-1_67.lib;C:/Program Files/lib/libboost_thread-vc141-mt-gd-x32-1_67.lib;C:/Program Files/lib/libboost_date_time-vc141-mt-gd-x32-1_67.lib;C:/Program Files/lib/libboost_regex-vc141-mt-gd-x32-1_67.lib;C:/Program Files/lib/libboost_timer-vc141-mt-gd-x32-1_67.lib;C:/Program Files/lib/libboost_chrono-vc141-mt-gd-x32-1_67.lib;metis
    
    This warning is for project developers.  Use -Wno-dev to suppress it.
    
  4. Frank Dellaert

    Confirming that I can build FixedLagSmoother example etc. Things like check build for me but then don't do anything.

  5. José Luis Blanco-Claraco reporter

    Thanks for checking! Then, I can't understand what's wrong with my MSVC build... will try in another PC.

    On the cmake warning: it should be fixed by PR #372 :-)

  6. José Luis Blanco-Claraco reporter

    I finally found a solution to this, Yay! But it includes changes in both, gtsam, and inside Eigen... Will clean up the code and propose it upstream to Eigen's authors to hear for their opinion. Cheers

  7. Log in to comment