我在学习中望3D的二次开发。目前在编译官方提供的api template的第三个示例开始出现了错误。
以下是我的开发环境:
Windows11 24H2、visual studio 2022、Windows 11 SDK (10.0.22621.0)、中望3D 2025 SP2。
编译api template示例第三个,ViewTool过程。按照官方文档配置了依赖的头文件、库文件和链接模块后,开始在release模式下编译。出现了如下错误:
生成开始于 17:19…
1>—— 已启动生成: 项目: ViewTool, 配置: Release x64 ——
1>ViewTool.c
1>C:\Program Files\ZWSOFT\ZW3D 2025\api\inc\zwapi_sketch_wireframe_data.h(145,15): error C2011: “uzwSketchReadyTextSettings”:“union”类型重定义
1>(编译源文件“ViewTool.c”)
1> C:\Program Files\ZWSOFT\ZW3D 2025\api\inc\zwapi_sketch_wireframe_data.h(122,15):
1> 参见“uzwSketchReadyTextSettings”的声明
1>C:\Program Files\ZWSOFT\ZW3D 2025\api\inc\zwapi_sketch_wireframe_data.h(149,19): error C2059: 语法错误:“;”
1>(编译源文件“ViewTool.c”)
1>C:\Program Files\ZWSOFT\ZW3D 2025\api\inc\zwapi_sketch_wireframe_data.h(150,5): error C2059: 语法错误:“}”
1>(编译源文件“ViewTool.c”)
1>C:\Program Files\ZWSOFT\ZW3D 2025\api\inc\zwapi_sketch_wireframe.h(152,99): error C2143: 语法错误: 缺少“)”(在“*”的前面)
1>(编译源文件“ViewTool.c”)
1>C:\Program Files\ZWSOFT\ZW3D 2025\api\inc\zwapi_sketch_wireframe.h(152,80): error C2081: “szwReadyTextCreate”: 形参表中的名称非法
1>(编译源文件“ViewTool.c”)
1>C:\Program Files\ZWSOFT\ZW3D 2025\api\inc\zwapi_sketch_wireframe.h(152,99): error C2143: 语法错误: 缺少“{”(在“*”的前面)
1>(编译源文件“ViewTool.c”)
1>C:\Program Files\ZWSOFT\ZW3D 2025\api\inc\zwapi_sketch_wireframe.h(152,104): error C2059: 语法错误:“)”
1>(编译源文件“ViewTool.c”)
1>C:\Program Files\ZWSOFT\ZW3D 2025\api\inc\zwapi_sketch_wireframe.h(181,67): error C2146: 语法错误: 缺少“)”(在标识符“data”的前面)
1>(编译源文件“ViewTool.c”)
1>C:\Program Files\ZWSOFT\ZW3D 2025\api\inc\zwapi_sketch_wireframe.h(181,67): error C2061: 语法错误: 标识符“data”
1>(编译源文件“ViewTool.c”)
1>C:\Program Files\ZWSOFT\ZW3D 2025\api\inc\zwapi_sketch_wireframe.h(181,67): error C2059: 语法错误:“;”
1>(编译源文件“ViewTool.c”)
1>C:\Program Files\ZWSOFT\ZW3D 2025\api\inc\zwapi_sketch_wireframe.h(181,71): error C2059: 语法错误:“,”
1>(编译源文件“ViewTool.c”)
1>C:\Program Files\ZWSOFT\ZW3D 2025\api\inc\zwapi_sketch_wireframe.h(181,102): error C2059: 语法错误:“)”
1>(编译源文件“ViewTool.c”)
1>已完成生成项目“ViewTool.vcxproj”的操作 – 失败。
========== 生成: 0 成功,1 失败,0 最新,0 已跳过 ==========
定位zwapi_sketch_wireframe.h源文件并谷歌搜索后附近发现C2011错误可能的原因是,union uzwSketchReadyTextSettings重复定义问题。具体代码如下:
/**
@brief data of ready sketch text
@ingroup ZwSketchData
*/
typedef struct szwReadyText
{
ezwReadyTextMethods methods; /**<@brief ready text methods */
szwPoint origin; /**<@brief text position */
szwPoint alignPoint; /**<@brief align Point, only used when methods is ZW_BOX */
char *textString; /**<@brief text string */
szwReadyTextFont font; /**<@brief the front settings of Sketch ready text */
szwSketchTextForm text; /**<@brief the text form setting of sketch ready text */
szwSketchReadyTextAlignment alignments; /**<@brief the text alignment of sketch ready text */
union uzwSketchReadyTextSettings /**<@brief union of sketch text data */
{
szwSketchOnCurveTextSettings onCurveSettings; /**<@brief the settings of on curve text data of sketch ready text */
szwSketchBoxTextSettings boxSettings; /**<@brief the settings of box text data of sketch ready text */
} settings;
} szwReadyText;
/**
@brief data to create ready text
@ingroup ZwSketchData
*/
typedef struct szwReadyTextCreate
{
ezwReadyTextMethods methods; /**<@brief ready text methods */
szwPointOnEntity origin; /**<@brief text position */
szwPointOnEntity alignPoint; /**<@brief Align Point, only when methods == ZW_BOX */
char *textString; /**<@brief text string */
szwReadyTextFont font; /**<@brief the front settings of Sketch ready text */
szwSketchTextForm text; /**<@brief the text form setting of sketch ready text */
szwSketchReadyTextAlignment alignments; /**<@brief the text alignment of sketch ready text */
union uzwSketchReadyTextSettings /**<@brief union of sketch text data */
{
szwSketchOnCurveTextSettings onCurveSettings; /**<@brief the settings of on curve text data of sketch ready text */
szwSketchBoxTextSettings boxSettings; /**<@brief the settings of box text data of sketch ready text */
} settings;
} szwReadyTextCreate;
各位有遇到这个问题吗?或者是我还有什么配置选项遗漏了?感谢大佬解答。