如何防止 xcode 4.0 自动在纯 cpp 文件中包含 objective-c 运行时标头

How to keep xcode 4.0 from automatically including objective-c runtime headers in plain cpp files

本文关键字:包含 文件 objective-c 运行时 cpp xcode 何防止      更新时间:2023-10-16

我正在尝试为iOS编译一个objective-c,c ++,c混合项目。我使用 llvm 2.0 编译器并将"编译源代码"设置为"根据文件类型"。我禁用了使用前缀标头(我希望),并努力寻找错误的 #import 应该 #include s。

在构建 cpp 文件时,我仍然收到编译错误,因为编译器出于某种原因尝试包含 NSObjectiveCRuntime.h。

我在构建设置中寻找错误的条目。如果仍指定了"前缀标头",则禁用"预编译前缀标头"不会执行任何操作。我通过以下方式解决了我的问题:

  • 创建新的 ProjectName_Prefix.pch
  • 通过目标构建设置中的"前缀标头"将其指定为我的目标预编译标头
  • 向其添加以下代码

    //
    //  Entourage_Prefix.pch
    //  Entourage
    //
    //  Created by Martin Lütke on 24.06.12.
    //  Copyright 2012 __MyCompanyName__. All rights reserved.
    //
    #include <string>
    #include <strstream>
    #include <vector>
    #include <map>
    #ifdef __OBJC__
            #import <Foundation/Foundation.h>
            #import <UIKit/UIKit.h>
            #import "cocos2d.h"
    #endif
    #ifdef __cplusplus
            #include <boost/shared_ptr.hpp>
            #include <boost/function.hpp>        
    #endif
    

    这将允许显式指定通过 objective-c 或 c++ 中的前缀标头包含的内容。

相关文章: