.mm 文件中的 Xcode 语法着色损坏

发布于 2024-12-19 22:03:21 字数 923 浏览 4 评论 0原文

几周来我一直在尝试调试这个问题,但进展为零。在我的一个项目中,我的 .mm 文件不再具有正确的语法着色,除了 @property、@synthesize 和基本类型(如 BOOL、int、double 等)之外。.cpp 文件很好。我已经尝试了几乎所有可以在网上找到的“修复”。我:

  1. 删除了组织者下项目的“派生数据”。
  2. 在 Finder 中右键单击项目的 .xcodeproject 文件,选择“显示包内容”并删除除 .pbxproj 文件之外的所有文件。
  3. 产品>干净地
  4. 与编辑搞砸了>语法着色选项。
  5. 确保我的所有标头搜索路径都使用“$(SRCROOT)/”前缀。
  6. 确保从这些路径导入的所有头文件都是通过以下方式导入的:

    #import ;
    

而不是:

    #import "header.h"

我觉得我没有选择。还有其他人有与我已经尝试过数百次的方法不同的修复方法吗?没有正确的语法着色让我发疯。

谢谢。

编辑:忘了提及,我还查看了 Console.app 中的日志并看到了以下内容:

12/5/11 3:08:08 PM Xcode[7623] [?T] IDEIndexingClangInspiration:无法保存 PCH 文件: /Users/jinser/Library/Developer/Xcode/DerivedData/ABBYY_MenuApp-ezwvcbulelfqwkftuwttlogvxsym/Index/PrecompiledHeaders/OpenCV_iPhone_Prefix-bqbegypvoktytjhgrfdzxrzeamix_ast/OpenCV_iPhone_Prefix.pch.pth

I've been trying to debug this issue for weeks now and I have made zero progress. In one of my projects, my .mm files no longer have the proper syntax coloring except for things like @property, @synthesize and primitive types like BOOL, int, double, etc. The .cpp files are fine. I've tried just about every 'fix' I could find on the web. I've:

  1. Deleted the 'Derived Data' for the project under Organizer.
  2. Right-clicked on the project's .xcodeproject file in Finder, selected 'Show Package Contents' and deleted all but the .pbxproj file.
  3. Product > Clean
  4. Messed around with the Editor > Syntax Coloring options.
  5. Ensured that all of my Header Search Paths were using the '$(SRCROOT)/' prefix.
  6. Ensured that all of the header files to be imported from these paths were imported by:

    #import <header.h>
    

instead of:

    #import "header.h"

I feel like I'm out of options. Does anyone else have a fix that is different from the things I've already tried hundreds of times? Not having the proper syntax coloring is driving me insane.

Thanks.

EDIT: Forgot to mention, I also looked at the log in Console.app and saw this:

12/5/11 3:08:08 PM Xcode[7623] [?T] IDEIndexingClangInvocation: Failed to save PCH file: /Users/jinser/Library/Developer/Xcode/DerivedData/ABBYY_MenuApp-ezwvcbulelfqwkftuwttlogvxsym/Index/PrecompiledHeaders/OpenCV_iPhone_Prefix-bqbegypvoktytjhgrfdzxrzeamix_ast/OpenCV_iPhone_Prefix.pch.pth

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

毁我热情 2024-12-26 22:03:21

您修改过 .pch 文件吗?如果您的 .pch 文件不完全正确,这可能会破坏索引器。例如,如果您在真正需要 #import 的地方使用 #import "header.h",则实际上可以正常编译文件(假设您的标头搜索路径设置为查找 header.h),但是,如果存在于 .pch 中,它将破坏索引器,因为它并不严格正确。

尝试删除 .pch 文件的内容,然后删除所有 DerivedData 并让 Xcode 重新索引。如果现在显示正确,那么您就知道您的 .pch 是问题所在。

Did you ever modify your .pch file? If you have a .pch file that isn't strictly correct, this can break the indexer. For example, if you use #import "header.h" where you really need #import <EmbeddedFramework/header.h>, this will actually compile just fine in regular files (assuming your header search paths are set up to find header.h) but, if present in the .pch, it will break the indexer as it's not strictly correct.

Try deleting the contents of your .pch file, then delete all DerivedData and let Xcode re-index. If things highlight correctly now, you know your .pch was the problem.

阳光①夏 2024-12-26 22:03:21

根据 Kevin Ballard 的建议,我将 .pch 文件从以下位置更改

#ifdef __OBJC__
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <opencv/cv.h>
#endif

为:

#ifdef __OBJC__
#import <UIKit/UIKit.h>
#import <opencv/cv.h>
#endif

在 Finder 中,我还通过转到 username/Library/Developer/Xcode/DerivedData 删除了相应的 Derived Data 文件夹。

瞧 - 语法现在已正确着色。我的疯狂终于平息了。

编辑(10 天后):不过我要补充一点,这并不总是有效。我的代码感觉再次被破坏,执行这些步骤并不能修复它。似乎每个案例都是独一无二的,每当发生这种情况时,您都必须浪费数小时的时间来尝试解决问题。希望 Apple 将来能够使 Xcode 对这些错误更加健壮。

Using Kevin Ballard's advice, I changed my .pch file from this:

#ifdef __OBJC__
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <opencv/cv.h>
#endif

to:

#ifdef __OBJC__
#import <UIKit/UIKit.h>
#import <opencv/cv.h>
#endif

In Finder, I also deleted the appropriate Derived Data folder by going to username/Library/Developer/Xcode/DerivedData.

Voilà - the syntax is now colored properly. My madness is finally subsiding.

EDIT (10 Days Later): I will add however that this does not always work. My code sense is again broken and performing these steps is not fixing it. Seems like each case is unique and you have to waste hours of your time trying to fix the issue whenever this happens. Hopefully Apple can make Xcode more robust to these errors in the future.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文