vs2012下编译别人的项目时,明明有头文件且xxx.cpp中包含的头文件,却还提示xxx是未标识符,error C2065

本文详细记录了解决在不同IDE(如Visual Studio和Xcode)下使用相同源码文件时,由于文本编码不一致导致的编译错误问题。通过分析错误原因,作者最终发现是文本编码格式不统一导致的问题,并提供了解决步骤:将与问题相关的文件转换为ASCII编码,删除原文件,新建同名文件并复制内容,成功解决了编译问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一大早起来,从网上下载了一个cocos2d-x游戏--三消类游戏Sushi Crush源码,看到网上运行效果的截图,觉得这源码很有学习的必要。

于是,我就用vs2012打开win32下的sln,编译却提示“c:\users\end\desktop\sushicrush-master\classes\play-layer.cpp(22): error  C2065: “m_srcSushi”: 未声明的标识符”等等未标明的错误。我擦,明明在playlayer.cpp中都包含了

playlayer.h,而且player.h中的类PlayLayer都有变量m_srcSushi等等,这就很郁闷。上网找了资料,都没有解决这个问题。于是乎自己就开始分析错误原因了,如下。

vs2012提示未声明的标识符,就说明#include"player.h"的内容没有包含进来,可是player.h都在啊?这就奇怪了。后来发现,原作者是在xcode下写代码的,我想会不会是文本的格式问题导致VS2012无法识别player.h的内容。好,就假设是这个原因造成的,于是我就把player.h的内容复制到一个txt中,这是为了把格式去掉,然后把原player.h删除,再新建一个player.h,把txt的内容复制到新的player.h中。好的,如果再次编译时,没有提示m_srcSushi等未标明的错误,就证明上面的假设是成立的。我再次点击了编译,等待了几秒。果然这次没有提示m_srcSushi等未标明的错误,证明了以上错误是不同IDE的文本格式造成的。

可是这个问题解决了,又提示“xxx 是未标明的变量”,我用查找功能,在整个项目中都没有找到xxx变量。我擦,明明没有xxx变量,你还提示xxx是未标明,甚是郁闷。好的,再次分析原因,有了上面的解决方法,我首先想到又可能是文本的格式照成的,于是照样画葫芦,再次编译,问题解决了。整个项目可运行了。

此时,看看时间,发现这个问题搞两个半小时了,我擦。

最后做一个总结。如果一个项目在两个不同的IDE中编写代码时,提示xxx是未标识符,可是与xxx相关的头文件都在相关的cpp中,此错误可能是不同的IDE文本格式造成的。解决方法是,首先去除与xxx有关的文件的格式,使它变成ASCCI格式,复制内容到别处。然后删除原与xxx相关的文件。最后新建与删除同名的文件,把去除格式后的内容复制到各新文件中。


/home/bobac3/ros_workspace/src/oryxbot_cruise_ex/src/oryxbot_cruise_ex.cpp:39:18: error: stray ‘\316’ in program if (|��θ| > 0.05) goto case 4; ^ /home/bobac3/ros_workspace/src/oryxbot_cruise_ex/src/oryxbot_cruise_ex.cpp:39:19: error: stray ‘\224’ in program if (|��θ| > 0.05) goto case 4; ^ /home/bobac3/ros_workspace/src/oryxbot_cruise_ex/src/oryxbot_cruise_ex.cpp:39:20: error: stray ‘\316’ in program if (|Δ��| > 0.05) goto case 4; ^ /home/bobac3/ros_workspace/src/oryxbot_cruise_ex/src/oryxbot_cruise_ex.cpp:39:21: error: stray ‘\270’ in program if (|Δ��| > 0.05) goto case 4; ^ /home/bobac3/ros_workspace/src/oryxbot_cruise_ex/src/oryxbot_cruise_ex.cpp:40:23: error: stray ‘\316’ in program else if (|��x|>0.01 || |Δy|>0.01) goto case 3; ^ /home/bobac3/ros_workspace/src/oryxbot_cruise_ex/src/oryxbot_cruise_ex.cpp:40:24: error: stray ‘\224’ in program else if (|��x|>0.01 || |Δy|>0.01) goto case 3; ^ /home/bobac3/ros_workspace/src/oryxbot_cruise_ex/src/oryxbot_cruise_ex.cpp:40:37: error: stray ‘\316’ in program else if (|Δx|>0.01 || |��y|>0.01) goto case 3; ^ /home/bobac3/ros_workspace/src/oryxbot_cruise_ex/src/oryxbot_cruise_ex.cpp:40:38: error: stray ‘\224’ in program else if (|Δx|>0.01 || |��y|>0.01) goto case 3; ^ /home/bobac3/ros_workspace/src/oryxbot_cruise_ex/src/oryxbot_cruise_ex.cpp:43:26: error: stray ‘\316’ in program RelativeMove(��x, Δy, 0); ^ /home/bobac3/ros_workspace/src/oryxbot_cruise_ex/src/oryxbot_cruise_ex.cpp:43:27: error: stray ‘\224’ in program RelativeMove(��x, Δy, 0); ^ /home/bobac3/ros_workspace/src/oryxbot_cruise_ex/src/oryxbot_cruise_ex.cpp:43:31: error: stray ‘\316’ in program RelativeMove(Δx, ��y, 0); ^ /home/bobac3/ros_workspace/src/oryxbot_cruise_ex/src/oryxbot_cruise_ex.cpp:43:32: error: stray ‘\224’ in program RelativeMove(Δx, ��y, 0); ^ /home/bobac3/ros_workspace/src/oryxbot_cruise_ex/src/oryxbot_cruise_ex.cpp:45:32: error: stray ‘\316’ in program RelativeMove(0, 0, ��θ); ^ /home/bobac3/ros_workspace/src/oryxbot_cruise_ex/src/oryxbot_cruise_ex.cpp:45:33: error: stray ‘\224’ in program RelativeMove(0, 0, ��θ); ^ /home/bobac3/ros_workspace/src/oryxbot_cruise_ex/src/oryxbot_cruise_ex.cpp:45:34: error: stray ‘\316’ in program RelativeMove(0, 0, Δ��); ^ /home/bobac3/ros_workspace/src/oryxbot_cruise_ex/src/oryxbot_cruise_ex.cpp:45:35: error: stray ‘\270’ in program RelativeMove(0, 0, Δ��); ^ /home/bobac3/ros_workspace/src/oryxbot_cruise_ex/src/oryxbot_cruise_ex.cpp: In function ‘geometry_msgs::Twist GetTargetAheadPose(geometry_msgs::Transform&)’: /home/bobac3/ros_workspace/src/oryxbot_cruise_ex/src/oryxbot_cruise_ex.cpp:19:5: error: ‘tf2’ has not been declared tf2::Transform baseToTargetTrans = GetTfPose(); ^~~ /home/bobac3/ros_workspace/src/oryxbot_cruise_ex/src/oryxbot_cruise_ex.cpp:22:5: error: ‘tf2’ has not been declared tf2::Transform baseToAheadTrans = baseToTargetTrans * targetToAheadTrans; ^~~ /home/bobac3/ros_workspace/src/oryxbot_cruise_ex/src/oryxbot_cruise_ex.cpp:25:5: error: ‘outPose’ was not declared in this scope outPose.linear.x = baseToAheadTrans.getOrigin().x(); ^~~~~~~ /home/bobac3/ros_workspace/src/oryxbot_cruise_ex/src/oryxbot_cruise_ex.cpp:25:5: note: suggested alternative: ‘boxPose_’ outPose.linear.x = baseToAheadTrans.getOrigin().x(); ^~~~~~~ boxPose_ /home/bobac3/ros_workspace/src/oryxbot_cruise_ex/src/oryxbot_cruise_ex.cpp:25:24: error: ‘baseToAheadTrans’ was not declared in this scope outPose.linear.x = baseToAheadTrans.getOrigin().x(); ^~~~~~~~~~~~~~~~ /home/bobac3/ros_workspace/src/oryxbot_cruise_ex/src/oryxbot_cruise_ex.cpp:27:5: error: ‘mat’ was not declared in this scope mat.getRPY(roll, pitch, outPose.angular.z); // 提取偏航角 ^~~ /home/bobac3/ros_workspace/src/oryxbot_cruise_ex/src/oryxbot_cruise_ex.cpp:27:5: note: suggested alternative: ‘fmaq’ mat.getRPY(roll, pitch, outPose.angular.z); // 提取偏航角 ^~~ fmaq /home/bobac3/ros_workspace/src/oryxbot_cruise_ex/src/oryxbot_cruise_ex.cpp:27:16: error: ‘roll’ was not declared in this scope mat.getRPY(roll, pitch, outPose.angular.z); // 提取偏航角 ^~~~ /home/bobac3/ros_workspace/src/oryxbot_cruise_ex/src/oryxbot_cruise_ex.cpp:27:16: note: suggested alternative: ‘atoll’ mat.getRPY(roll, pitch, outPose.angular.z); // 提取偏航角 ^~~~ atoll /home/bobac3/ros_workspace/src/oryxbot_cruise_ex/src/oryxbot_cruise_ex.cpp:27:22: error: ‘pitch’ was not declared in this scope mat.getRPY(roll, pitch, outPose.angular.z); // 提取偏航角 ^~~~~ /home/bobac3/ros_workspace/src/oryxbot_cruise_ex/src/oryxbot_cruise_ex.cpp:27:22: note: suggested alternative: ‘putc’ mat.getRPY(roll, pitch, outPose.angular.z); // 提取偏航角 ^~~~~ putc /home/bobac3/ros_workspace/src/oryxbot_cruise_ex/src/oryxbot_cruise_ex.cpp: In function ‘bool TrackCb(ar_pose::Track::Request&, ar_pose::Track::Response&)’: /home/bobac3/ros_workspace/src/oryxbot_cruise_ex/src/oryxbot_cruise_ex.cpp:33:13: error: ‘step’ was not declared in this scope switch (step) { ^~~~ /home/bobac3/ros_workspace/src/oryxbot_cruise_ex/src/oryxbot_cruise_ex.cpp:33:13: note: suggested alternative: ‘strsep’ switch (step) { ^~~~ strsep /home/bobac3/ros_workspace/src/oryxbot_cruise_ex/src/oryxbot_cruise_ex.cpp:35:17: error: ‘FindTarget’ was not declared in this scope if (FindTarget() < 0) return error; ^~~~~~~~~~ /home/bobac3/ros_workspace/src/oryxbot_cruise_ex/src/oryxbot_cruise_ex.cpp:35:42: error: ‘error’ was not declared in this scope if (FindTarget() < 0) return error; ^~~~~ /home/bobac3/ros_workspace/src/oryxbot_cruise_ex/src/oryxbot_cruise_ex.cpp:35:42: note: suggested alternative: ‘perror’ if (FindTarget() < 0) return error; ^~~~~ perror /home/bobac3/ros_workspace/src/oryxbot_cruise_ex/src/oryxbot_cruise_ex.cpp:37:26: error: ‘targetPose’ was not declared in this scope RelativeMove(targetPose.linear.x, targetPose.linear.y, targetPose.angular.z); ^~~~~~~~~~ /home/bobac3/ros_workspace/src/oryxbot_cruise_ex/src/oryxbot_cruise_ex.cpp:37:26: note: suggested alternative: ‘fgetpos’ RelativeMove(targetPose.linear.x, targetPose.linear.y, targetPose.angular.z); ^~~~~~~~~~ fgetpos /home/bobac3/ros_workspace/src/oryxbot_cruise_ex/src/oryxbot_cruise_ex.cpp:37:13: error: ‘RelativeMove’ was not declared in this scope RelativeMove(targetPose.linear.x, targetPose.linear.y, targetPose.angular.z); ^~~~~~~~~~~~ /home/bobac3/ros_workspace/src/oryxbot_cruise_ex/src/oryxbot_cruise_ex.cpp:39:17: error: expected primary-expression before ‘|’ token if (|Δθ| > 0.05) goto case 4; ^ /home/bobac3/ros_workspace/src/oryxbot_cruise_ex/src/oryxbot_cruise_ex.cpp:39:22: error: expected primary-expression before ‘|’ token if (|Δθ| > 0.05) goto case 4; ^ /home/bobac3/ros_workspace/src/oryxbot_cruise_ex/src/oryxbot_cruise_ex.cpp:39:24: error: expected primary-expression before ‘>’ token if (|Δθ| > 0.05) goto case 4; ^ /home/bobac3/ros_workspace/src/oryxbot_cruise_ex/src/oryxbot_cruise_ex.cpp:39:37: error: expected identifier before ‘case’ if (|Δθ| > 0.05) goto case 4; ^~~~ /home/bobac3/ros_workspace/src/oryxbot_cruise_ex/src/oryxbot_cruise_ex.cpp:39:37: error: expected ‘;’ before ‘case’ /home/bobac3/ros_workspace/src/oryxbot_cruise_ex/src/oryxbot_cruise_ex.cpp:39:43: error: expected ‘:’ before ‘;’ token if (|Δθ| > 0.05) goto case 4; ^ /home/bobac3/ros_workspace/src/oryxbot_cruise_ex/src/oryxbot_cruise_ex.cpp:40:13: error: ‘else’ without a previous ‘if’ else if (|Δx|>0.01 || |Δy|>0.01) goto case 3; ^~~~ /home/bobac3/ros_workspace/src/oryxbot_cruise_ex/src/oryxbot_cruise_ex.cpp:40:22: error: expected primary-expression before ‘|’ token else if (|Δx|>0.01 || |Δy|>0.01) goto case 3; ^ /home/bobac3/ros_workspace/src/oryxbot_cruise_ex/src/oryxbot_cruise_ex.cpp:40:25: error: ‘x’ was not declared in this scope else if (|Δx|>0.01 || |Δy|>0.01) goto case 3; ^ /home/bobac3/ros_workspace/src/oryxbot_cruise_ex/src/oryxbot_cruise_ex.cpp:40:27: error: expected primary-expression before ‘>’ token else if (|Δx|>0.01 || |Δy|>0.01) goto case 3; ^ /home/bobac3/ros_workspace/src/oryxbot_cruise_ex/src/oryxbot_cruise_ex.cpp:40:36: error: expected primary-expression before ‘|’ token else if (|Δx|>0.01 || |Δy|>0.01) goto case 3; ^ /home/bobac3/ros_workspace/src/oryxbot_cruise_ex/src/oryxbot_cruise_ex.cpp:40:39: error: ‘y’ was not declared in this scope else if (|Δx|>0.01 || |Δy|>0.01) goto case 3; ^ /home/bobac3/ros_workspace/src/oryxbot_cruise_ex/src/oryxbot_cruise_ex.cpp:40:39: note: suggested alternative: ‘yn’ else if (|Δx|>0.01 || |Δy|>0.01) goto case 3; ^ yn /home/bobac3/ros_workspace/src/oryxbot_cruise_ex/src/oryxbot_cruise_ex.cpp:40:41: error: expected primary-expression before ‘>’ token else if (|Δx|>0.01 || |Δy|>0.01) goto case 3; ^ /home/bobac3/ros_workspace/src/oryxbot_cruise_ex/src/oryxbot_cruise_ex.cpp:40:53: error: expected identifier before ‘case’ else if (|Δx|>0.01 || |Δy|>0.01) goto case 3; ^~~~ /home/bobac3/ros_workspace/src/oryxbot_cruise_ex/src/oryxbot_cruise_ex.cpp:40:53: error: expected ‘;’ before ‘case’ /home/bobac3/ros_workspace/src/oryxbot_cruise_ex/src/oryxbot_cruise_ex.cpp:40:59: error: expected ‘:’ before ‘;’ token else if (|Δx|>0.01 || |Δy|>0.01) goto case 3; ^ /home/bobac3/ros_workspace/src/oryxbot_cruise_ex/src/oryxbot_cruise_ex.cpp:41:13: error: ‘else’ without a previous ‘if’ else goto case 5; ^~~~ /home/bobac3/ros_workspace/src/oryxbot_cruise_ex/src/oryxbot_cruise_ex.cpp:41:23: error: expected identifier before ‘case’ else goto case 5; ^~~~ /home/bobac3/ros_workspace/src/oryxbot_cruise_ex/src/oryxbot_cruise_ex.cpp:41:23: error: expected ‘;’ before ‘case’ /home/bobac3/ros_workspace/src/oryxbot_cruise_ex/src/oryxbot_cruise_ex.cpp:41:29: error: expected ‘:’ before ‘;’ token else goto case 5; ^ /home/bobac3/ros_workspace/src/oryxbot_cruise_ex/src/oryxbot_cruise_ex.cpp:43:28: error: ‘x’ was not declared in this scope RelativeMove(Δx, Δy, 0); ^ /home/bobac3/ros_workspace/src/oryxbot_cruise_ex/src/oryxbot_cruise_ex.cpp:43:33: error: ‘y’ was not declared in this scope RelativeMove(Δx, Δy, 0); ^ /home/bobac3/ros_workspace/src/oryxbot_cruise_ex/src/oryxbot_cruise_ex.cpp:43:33: note: suggested alternative: ‘yn’ RelativeMove(Δx, Δy, 0); ^ yn /home/bobac3/ros_workspace/src/oryxbot_cruise_ex/src/oryxbot_cruise_ex.cpp:45:36: error: expected primary-expression before ‘)’ token RelativeMove(0, 0, Δθ); ^ /home/bobac3/ros_workspace/src/oryxbot_cruise_ex/src/oryxbot_cruise_ex.cpp:47:13: error: ‘SetFinishedFlag’ was not declared in this scope SetFinishedFlag(true); ^~~~~~~~~~~~~~~ /home/bobac3/ros_workspace/src/oryxbot_cruise_ex/src/oryxbot_cruise_ex.cpp: In function ‘int8_t RelativeMove(double, double, double)’: /home/bobac3/ros_workspace/src/oryxbot_cruise_ex/src/oryxbot_cruise_ex.cpp:52:5: error: ‘cmd’ was not declared in this scope cmd.request.global_frame = "odom"; // 使用odom坐标系 ^~~ /home/bobac3/ros_workspace/src/oryxbot_cruise_ex/src/oryxbot_cruise_ex.cpp:56:5: error: ‘relativeMoveClient_’ was not declared in this scope relativeMoveClient_.call(cmd); // 调用服务 ^~~~~~~~~~~~~~~~~~~ /home/bobac3/ros_workspace/src/oryxbot_cruise_ex/src/oryxbot_cruise_ex.cpp:56:5: note: suggested alternative: ‘RelativeMove’ relativeMoveClient_.call(cmd); // 调用服务 ^~~~~~~~~~~~~~~~~~~
06-29
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值