将空c ++文件添加到xcode项目会在obj-c头文件中创建语法错误

时间:2016-01-07 22:46:10

标签: c++ ios objective-c xcode

我正在努力将代码添加到使用card.io项目的现有iphone应用程序(由其他人编写)。这是我尝试过的第一个改变。该应用程序编译并运行正常,没有任何更改,但当我尝试将空的.cpp和.h文件添加到我的xcode项目时,我开始在一个名为CardIOMacros.h的无关的obj-c头文件中获取语法错误。我正在使用xcode 7.2并编译为iphone 4s设备。

我完成添加.cpp和.h文件的过程是

  1. 右键单击项目导航器中的项目节点
  2. 点击新文件
  3. 点击c ++图标
  4. 文件的类型名称并检查创建标题文件选项
  5. 选择项目目录中的子目录。
  6. 按主菜单中的构建和运行按钮
  7. 以下是我收到错误的文件。错误显示在代码下方。

    //
    //  CardIOMacros.h
    //  See the file "LICENSE.md" for the full license governing this code.
    //
    
    // CardIOLog is a replacement for NSLog that logs iff CARDIO_DEBUG is set.
    
    #if CARDIO_DEBUG
    #define CardIOLog(format, args...) NSLog(format, ## args)
    #else
    #define CardIOLog(format, args...)
    #endif
    
    @interface CardIOMacros : NSObject
    
    + (id)localSettingForKey:(NSString *)key defaultValue:(NSString *)defaultValue productionValue:(NSString *)productionValue;
    
    + (NSUInteger)deviceSystemMajorVersion; 
    
    + (BOOL)appHasViewControllerBasedStatusBar; 
    
    @end
    
    #define iOS_MAJOR_VERSION  [CardIOMacros deviceSystemMajorVersion]
    #define iOS_8_PLUS         (iOS_MAJOR_VERSION >= 8)
    #define iOS_7_PLUS         (iOS_MAJOR_VERSION >= 7)
    #define iOS_6              (iOS_MAJOR_VERSION == 6)
    #define iOS_5              (iOS_MAJOR_VERSION == 5)
    

    Compliler错误

    /Users/michael/sdev/projectname/ios/card.io-iOS-20151210/Classes/CardIOMacros.h
    /Users/michael/sdev/projectname/ios/card.io-iOS-20151210/Classes/CardIOMacros.h:14:1: Expected unqualified-id
    /Users/michael/sdev/projectname/ios/card.io-iOS-20151210/Classes/CardIOMacros.h:18:1: Expected external declaration
    /Users/michael/sdev/projectname/ios/card.io-iOS-20151210/Classes/CardIOMacros.h:18:4: C++ requires a type specifier for all declarations
    /Users/michael/sdev/projectname/ios/card.io-iOS-20151210/Classes/CardIOMacros.h:18:15: Expected ';' after top level declarator
    /Users/michael/sdev/projectname/ios/card.io-iOS-20151210/Classes/CardIOMacros.h:20:1: Expected external declaration
    /Users/michael/sdev/projectname/ios/card.io-iOS-20151210/Classes/CardIOMacros.h:20:4: C++ requires a type specifier for all declarations
    /Users/michael/sdev/projectname/ios/card.io-iOS-20151210/Classes/CardIOMacros.h:20:9: Expected ';' after top level declarator
    /Users/michael/sdev/projectname/ios/card.io-iOS-20151210/Classes/CardIOMacros.h:22:1: Expected unqualified-id
    

    .h和.cpp文件为空,我甚至不在任何其他文件中#include新的c ++头文件。任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:1)

确保...-Prefix.pch中没有包含所述标题。