You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Boost Geometry编译xmsinterp库时遇编译错误求助

Boost Geometry引入Delaunay三角剖分后编译错误解决建议

环境与问题概述

  • 编译环境:Microsoft Visual Studio Community Edition 2022
  • 使用库:xmsinterp(此前编译正常)
  • 触发场景:引入依赖Boost Geometry模块的Delaunay三角剖分代码后,出现大量编译错误,错误均指向Boost Geometry的cartesian.hpp(centroid策略相关)

头文件包含情况

//  Boost Codes
#include <boost/bind/bind.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <boost/archive/text_oarchive.hpp>
#include <boost/serialization/export.hpp>
#include <boost/serialization/vector.hpp>
#include <boost/unordered_set.hpp>

#include <boost/geometry.hpp>
#include <boost/geometry/geometries/geometries.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/polygon.hpp>
//#include <boost/geometry/strategies/default_strategy.hpp>
//#include <boost/geometry/algorithms/centroid.hpp>
#include <boost/geometry/index/rtree.hpp>

using namespace boost::geometry;

#include <boost/unordered_map.hpp>
#include <boost/iterator/counting_iterator.hpp>

//  xmscore codes...
#include <xmscore/math/math.h>
#include <xmscore/stl/utility.h>
#include <xmscore/xmscore/points/ptsfwd.h>
//#include <xmsgrid/geometry/GmBoostTypes.h>
#include <xmsgrid/geometry/geoms.h>
#include <xmsgrid/geometry/GmPtSearch.h>
#include <xmscore/misc/xmstype.h>
#include <xmscore/misc/XmError.h>
#include <xmscore/misc/XmConst.h>

//  xmsgrid codes...
#include <xmsgrid/geometry/GmBoostTypes.h>
#include <xmsgrid/geometry/GmTriSearch.h>

//  xmsinterp codes...
#include <new.h>
#include <xmscore/misc/xmstype.h>
#include <xmsinterp/interpolate/detail/InterpCt.h>
#include <xmscore/stl/vector.h>
#include <xmsinterp/interpolate/detail/InterpCt.cpp>
#include <xmsinterp/interpolate/detail/NodalFunc.cpp>

//  xmsinterp test cases...
#include <xmsinterp/interpolate/InterpIdw.h>
#include <xmsinterp/interpolate/InterpLinear.h>
#include <xmsinterp/interpolate/InterpAnisotropic.h>
#include <xmsgrid/triangulate/TrTriangulator.h>

#include <xmsgrid/triangulate/TrTriangulatorPoints.h>
#include <xmsgrid/triangulate/detail/triangulate.h>

编译错误信息

.\boost\libs\geometry\include\boost\geometry\strategies\centroid\cartesian.hpp(90,10): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
.\boost\libs\geometry\include\boost\geometry\strategies\centroid\cartesian.hpp(90,20): error C2059: syntax error: 'constant'
.\boost\libs\geometry\include\boost\geometry\strategies\centroid\cartesian.hpp(91,59): error C2065: 'PG': undeclared identifier
.\boost\libs\geometry\include\boost\geometry\strategies\centroid\cartesian.hpp(91,47): error C2974: 'boost::geometry::strategy::centroid::average': invalid template argument for 'Ignored1', type expected
.\boost\libs\geometry\include\boost\geometry\strategies\cartesian\centroid_average.hpp(51): message : see declaration of 'boost::geometry::strategy::centroid::average'
.\boost\libs\geometry\include\boost\geometry\strategies\centroid\cartesian.hpp(91,47): error C2923: 'boost::geometry::strategy::centroid::average': 'PG' is not a valid template type argument for parameter 'Ignored2'
.\boost\libs\geometry\include\boost\geometry\strategies\centroid\cartesian.hpp(91): message : see declaration of 'PG'
.\boost\libs\geometry\include\boost\geometry\strategies\centroid\cartesian.hpp(91,47): error C3203: 'average': unspecialized class template can't be used as a template argument for template parameter 'Strategy', expected a real type
.\boost\libs\geometry\include\boost\geometry\strategies\centroid\cartesian.hpp(92,1): error C2906: 'boost::geometry::strategies::centroid::services::strategy_converter<int>': explicit specialization requires 'template <>'
.\boost\libs\geometry\include\boost\geometry\strategies\centroid\cartesian.hpp(99,10): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
.\boost\libs\geometry\include\boost\geometry\strategies\centroid\cartesian.hpp(99,20): error C2059: syntax error: 'constant'
.\boost\libs\geometry\include\boost\geometry\strategies\centroid\cartesian.hpp(100,67): error C2065: 'PG': undeclared identifier
.\boost\libs\geometry\include\boost\geometry\strategies\centroid\cartesian.hpp(100,47): error C2974: 'boost::geometry::strategy::centroid::weighted_length': invalid template argument for 'Ignored1', type expected
.\boost\libs\geometry\include\boost\geometry\strategies\cartesian\centroid_weighted_length.hpp(49): message : see declaration of 'boost::geometry::strategy::centroid::weighted_length'
.\boost\libs\geometry\include\boost\geometry\strategies\centroid\cartesian.hpp(100,47): error C2923: 'boost::geometry::strategy::centroid::weighted_length': 'PG' is not a valid template type argument for parameter 'Ignored2'
.\boost\libs\geometry\include\boost\geometry\strategies\centroid\cartesian.hpp(100): message : see declaration of 'PG'
.\boost\libs\geometry\include\boost\geometry\strategies\centroid\cartesian.hpp(100,47): error C2976: 'boost::geometry::strategy::centroid::weighted_length': too few template arguments
.\boost\libs\geometry\include\boost\geometry\strategies\cartesian\centroid_weighted_length.hpp(49): message : see declaration of 'boost::geometry::strategy::centroid::weighted_length'
.\boost\libs\geometry\include\boost\geometry\strategies\centroid\cartesian.hpp(100,47): error C3203: 'weighted_length': unspecialized class template can't be used as a template argument for template parameter 'Strategy', expected a real type
.\boost\libs\geometry\include\boost\geometry\strategies\centroid\cartesian.hpp(101,1): error C2906: 'boost::geometry::strategies::centroid::services::strategy_converter<int>': explicit specialization requires 'template <>'
.\boost\libs\geometry\include\boost\geometry\strategies\centroid\cartesian.hpp(108,10): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
.\boost\libs\geometry\include\boost\geometry\strategies\centroid\cartesian.hpp(108,20): error C2059: syntax error: 'constant'
.\boost\libs\geometry\include\boost\geometry\strategies\centroid\cartesian.hpp(109,66): error C2065: 'PG': undeclared identifier
.\boost\libs\geometry\include\boost\geometry\strategies\centroid\cartesian.hpp(109,70): error C2065: 'CT': undeclared identifier
.\boost\libs\geometry\include\boost\geometry\strategies\centroid\cartesian.hpp(109,47): error C2974: 'boost::geometry::strategy::centroid::bashein_detmer': invalid template argument for 'Ignored1', type expected
.\boost\libs\geometry\include\boost\geometry\strategies\cartesian\centroid_bashein_detmer.hpp(126): message : see declaration of 'boost::geometry::strategy::centroid::bashein_detmer'
.\boost\libs\geometry\include\boost\geometry\strategies\centroid\cartesian.hpp(109,47): error C2923: 'boost::geometry::strategy::centroid::bashein_detmer': 'PG' is not a valid template type argument for parameter 'Ignored2'
.\boost\libs\geometry\include\boost\geometry\strategies\centroid\cartesian.hpp(109): message : see declaration of 'PG'
.\boost\libs\geometry\include\boost\geometry\strategies\centroid\cartesian.hpp(109,47): error C2923: 'boost::geometry::strategy::centroid::bashein_detmer': 'CT' is not a valid template type argument for parameter 'CalculationType'
.\boost\libs\geometry\include\boost\geometry\strategies\centroid\cartesian.hpp(109): message : see declaration of 'CT'
.\boost\libs\geometry\include\boost\geometry\strategies\centroid\cartesian.hpp(109,47): error C3203: 'bashein_detmer': unspecialized class template can't be used as a template argument for template parameter 'Strategy', expected a real type

.\boost\libs\geometry\include\boost\geometry\strategies\centroid\cartesian.hpp(110,1): error C2906: 'boost::geometry::strategies::centroid::services::strategy_converter<int>': explicit specialization requires 'template <>'

解决建议

  • 调整头文件包含顺序:将#include <xmsgrid/geometry/GmBoostTypes.h>移至所有Boost Geometry头文件之前。该文件大概率定义了Boost Geometry依赖的点类型(即错误中的PG),当前先包含Boost Geometry再包含该文件,导致编译时PG未声明。
  • 移除直接包含的.cpp文件:删除#include <xmsinterp/interpolate/detail/InterpCt.cpp>和#include <xmsinterp/interpolate/detail/NodalFunc.cpp>,直接包含源文件会破坏编译上下文,导致重复定义或类型解析错误,应通过项目编译源文件而非头文件包含。
  • 显式包含缺失的头文件:取消注释#include <boost/geometry/algorithms/centroid.hpp>,错误涉及centroid策略的模板参数解析,该头文件包含了必要的类型和策略定义。
  • 检查Boost版本兼容性:确认使用的Boost版本与xmsinterp库要求的版本匹配,版本不兼容会导致模板接口不匹配,引发此类编译错误。
  • 避免全局命名空间:移除using namespace boost::geometry;,改用boost::geometry::前缀限定相关类型,防止与xms库的类型名冲突。
  • 确认C++标准版本:在VS项目属性中设置C标准为C17或更高(Boost Geometry较新版本依赖C++17特性),同时确保Boost库是用对应标准编译的。
  • 清理并重新生成项目:清理VS解决方案的中间文件和缓存,然后重新生成项目,排除缓存导致的异常编译错误。

内容的提问来源于stack exchange,提问作者STBoerner

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.19 03:15:31