MSVC编译遇到C2059、C2143、C2059、C2365、C2059等错误的解决方案

发布于:2025-04-03 ⋅ 阅读:(13) ⋅ 点赞:(0)

在这里插入图片描述
MSVC编译时,遇到如下错误:

c:\program files (x86)\windows kits\10\include\10.0.18362.0\um\msxml.h(1842): error C2059: 语法错误:“常数” [D:\jenkins_home\workspace\xxx.vcxproj]
c:\program files (x86)\windows kits\10\include\10.0.18362.0\um\msxml.h(1842): error C2143: 语法错误: 缺少“;”(在“)”的前面) [D:\jenkins_home\workspace\xxx\xxx\xxx.vcxproj]
c:\program files (x86)\windows kits\10\include\10.0.18362.0\um\msxml.h(1842): error C2059: 语法错误:“)” [D:\jenkins_home\workspace\xxx\xxx\xxx.vcxproj]
c:\program files (x86)\windows kits\10\include\10.0.18362.0\um\msxml.h(1897): error C2365: “abort”: 重定义;以前的定义是“函数” [D:\jenkins_home\workspace\xxx\xxx\xxx.vcxproj]
C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\ucrt\stdlib.h(56): note: 参见“abort”的声明
c:\program files (x86)\windows kits\10\include\10.0.18362.0\um\msxml.h(1945): error C2059: 语法错误:“}” [D:\jenkins_home\workspace\xxx\xxx\xxx.vcxproj]
aaa.c
c:\program files (x86)\windows kits\10\include\10.0.18362.0\um\msxml.h(1842): error C2059: 语法错误:“常数” [D:\jenkins_home\workspace\xxx\xxx\xxx.vcxproj]
c:\program files (x86)\windows kits\10\include\10.0.18362.0\um\msxml.h(1842): error C2143: 语法错误: 缺少“;”(在“)”的前面) [D:\jenkins_home\workspace\xxx\xxx\xxx.vcxproj]
c:\program files (x86)\windows kits\10\include\10.0.18362.0\um\msxml.h(1842): error C2059: 语法错误:“)” [D:\jenkins_home\workspace\xxx\xxx\xxx.vcxproj]
c:\program files (x86)\windows kits\10\include\10.0.18362.0\um\msxml.h(1897): error C2365: “abort”: 重定义;以前的定义是“函数” [D:\jenkins_home\workspace\xxx\xxx\xxx.vcxproj]
C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\ucrt\stdlib.h(56): note: 参见“abort”的声明
c:\program files (x86)\windows kits\10\include\10.0.18362.0\um\msxml.h(1945): error C2059: 语法错误:“}” [D:\jenkins_home\workspace\xxx\xxx\xxx.vcxproj]
bbb.c
c:\program files (x86)\windows kits\10\include\10.0.18362.0\um\msxml.h(1842): error C2059: 语法错误:“常数” [D:\jenkins_home\workspace\xxx\xxx\xxx.vcxproj]
c:\program files (x86)\windows kits\10\include\10.0.18362.0\um\msxml.h(1842): error C2143: 语法错误: 缺少“;”(在“)”的前面) [D:\jenkins_home\workspace\xxx\xxx\xxx.vcxproj]
c:\program files (x86)\windows kits\10\include\10.0.18362.0\um\msxml.h(1842): error C2059: 语法错误:“)” [D:\jenkins_home\workspace\xxx\xxx\xxx.vcxproj]
c:\program files (x86)\windows kits\10\include\10.0.18362.0\um\msxml.h(1897): error C2365: “abort”: 重定义;以前的定义是“函数” [D:\jenkins_home\workspace\xxx\xxx\xxx.vcxproj]
C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\ucrt\stdlib.h(56): note: 参见“abort”的声明
c:\program files (x86)\windows kits\10\include\10.0.18362.0\um\msxml.h(1945): error C2059: 语法错误:“}” [D:\jenkins_home\workspace\xxx\xxx\xxx.vcxproj]
D:\jenkins_home\workspace\xxx\xxx\xxx\xxx\xxx\model\xxx.c(291): warning C4090: “函数”: 不同的“const”限定符 [D:\jenkins_home\workspace\xxx\xxx\xxx.vcxproj]
D:\jenkins_home\workspace\xxx\xxx\xxx\xxx\xxx\model\xxx.c(298): warning C4090: “函数”: 不同的“const”限定符 [D:\jenkins_home\workspace\xxx\xxx\xxx.vcxproj]
ccc.c

根据提示找到.c文件,发现代码也没有问题,也不是报的语法错误。

于是继续根据提示找到msxml.h文件的1842行,发现函数参数列表里有个pi,恰巧项目代码内有个宏定义是#define pi 3.14159
在这里插入图片描述

找到原因,是因宏定义与某些变量名冲突所致。

修改宏常量名称,再次编译,问题解决。


总结: 该类问题,一般都是由于重复定义或定义冲突等原因造成,尤其是在定义宏时尽可能避免简单字眼,防止与某些第三方库或代码发生冲突。


网站公告

今日签到

点亮在社区的每一天
去签到