weixin_39611389 2020-11-30 02:47
浏览 0

Silent warning C4251 when using DLL on Windows

Original issue 147 created by sandwichmaker on 2014-05-14T10:43:22.000Z:

I realized that I have introduced a new warning when using a DLL installation of Ceres on Windows.

When the user includes <ceres/ceres.h> they will se a dozen warnings of the type: warning C4251: 'ceres::CostFunction::parameter_block_sizes_' : class 'std::vector<ceres::int32,std::allocator<_Ty>>' needs to have dll-interface to be used by clients of class 'ceres::CostFunction'

I missed this because C4251 has been silenced in the Ceres CMakeLists.txt.

The MSDN documentation clearly states that this warning can be ignored when it comes to stl classes, but it sould be documented how to shut it up.

There are a couple ways to work around this: 1. Tell the user to add the following to there CMakeLists.txt:

IF (MSVC) # Disable the warning C4251 which is trigerred by stl classes in # Ceres' public interface. To quote MSDN: "C4251 can be ignored " # "if you are deriving from a type in the Standard C++ Library" ADD_DEFINITIONS("/wd4251") ENDIF (MSVC) 1. Alternatively, tell the user to include Ceres like this:

ifdef _MSC_VER

// Disable the warning C4251 which is trigerred by stl classes in // Ceres' public interface. To quote MSDN: "C4251 can be ignored " // "if you are deriving from a type in the Standard C++ Library"

pragma warning( push )

pragma warning( disable : 4252 )

endif

include <ceres/ceres.h>

ifdef _MSC_VER

pragma warning( pop )

endif

3: Or do this for the user like Eigen does with DisableStupidWarnings.h and ReenableStupidWarnings.h.

该提问来源于开源项目:ceres-solver/ceres-solver

  • 写回答

6条回答 默认 最新

  • weixin_39611389 2020-11-30 02:47
    关注

    Comment #1 originally posted by sandwichmaker on 2014-05-14T13:20:10.000Z:

    Bjorn, Thanks for reporting this. 1. Just doing this in ceres.h is not enough, since users may just include one of the headers in include/ceres directly. 2. perhaps we can do # 2 for all public headers. will that be a problem?

    评论

报告相同问题?