【问题标题】:What settings are needed in Xcode to get this code to build在 Xcode 中需要哪些设置来构建此代码
【发布时间】:2020-10-22 21:10:28
【问题描述】:

让我们来看看这段代码,它在一个头文件中。项目本身是 Objective-C++(.h 和 .mm 文件)。

这看起来像是 C++ 和 Objective-C 的混合体。根据我的阅读,为了将 Objective-C++ 与 Objective-C 混合,您必须将所有 C++ 内容保留在头文件之外,但事实并非如此。

项目构建良好,但是我无法在新项目中复制它(通过复制相同的代码)。

在 Xcode 中需要哪些设置来构建它?已经比较了项目构建设置,它们是相同的。

错误与 Options 结构中的内联初始化程序有关。

/*
  This file is part of the Structure SDK.
  Copyright © 2019 Occipital, Inc. All rights reserved.
  http://structure.io
*/

#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>

#import <Structure/Structure.h>
#import <Structure/STCaptureSession.h>

#import "CalibrationOverlay.h"
#import "MeshViewController.h"
#import "SettingsPopupView.h"

// See default initialization in: -(void)initializeDynamicOptions
struct DynamicOptions
{
    bool depthAndColorTrackerIsOn;
    bool improvedTrackingIsOn;
    bool highResColoring;
    bool improvedMapperIsOn;
    bool highResMapping;
    STCaptureSessionPreset depthStreamPreset;
};

struct Options
{
    // The initial scanning volume size will be 0.5 x 0.5 x 0.5 meters
    // (X is left-right, Y is up-down, Z is forward-back)
    const GLKVector3 initVolumeSizeInMeters = GLKVector3Make (0.5f, 0.5f, 0.5f);
    
    // The maximum number of keyframes saved in keyFrameManager
    int maxNumKeyFrames = 48;
    
    // Colorizer quality
    STColorizerQuality colorizerQuality = STColorizerHighQuality;
    
    // Take a new keyframe in the rotation difference is higher than 20 degrees.
    float maxKeyFrameRotation = 20.0f * (M_PI / 180.f); // 20 degrees
    
    // Take a new keyframe if the translation difference is higher than 30 cm.
    float maxKeyFrameTranslation = 0.3; // 30cm

    // Threshold to consider that the rotation motion was small enough for a frame to be accepted
    // as a keyframe. This avoids capturing keyframes with strong motion blur / rolling shutter.
    float maxKeyframeRotationSpeedInDegreesPerSecond = 1.f;
    
    // Whether we should use depth aligned to the color viewpoint when Structure Sensor was calibrated.
    // This setting may get overwritten to false if no color camera can be used.
    bool useHardwareRegisteredDepth = false;
    
    // Whether to enable an expensive per-frame depth accuracy refinement.
    // Note: this option requires useHardwareRegisteredDepth to be set to false.
    const bool applyExpensiveCorrectionToDepth = true;
    
    // Whether the colorizer should try harder to preserve appearance of the first keyframe.
    // Recommended for face scans.
    bool prioritizeFirstFrameColor = true;
    
    // Target number of faces of the final textured mesh.
    int colorizerTargetNumFaces = 50000;
    
    // Focus position for the color camera (between 0 and 1). Must remain fixed one depth streaming
    // has started when using hardware registered depth.
    const float lensPosition = 0.75f;
};

...
@interface ViewController : UIViewController <STBackgroundTaskDelegate, MeshViewDelegate, AVCaptureVideoDataOutputSampleBufferDelegate, UIPopoverControllerDelegate, UIGestureRecognizerDelegate, SettingsPopupViewDelegate>
{
...
}
@end

还有一些关于错误的细节:

【问题讨论】:

  • @interface .. @end@implementation .. @end 语句之外的任何内容实际上都是纯 C 或 C++,所以这里是 C++。
  • @OlSen 这很有趣。但它仍然没有解释为什么它不在新项目中构建。
  • 提示:过去我们使用 .hh 来告诉 Xcode 该文件是 C++ 或 ObjC++ 头文件。在我对您的 Options struct compile 问题的其他回答中,您看到我用#ifdef 语句定义了包含代码的语言规则集
  • 通常有很大帮助的是让 Xcode 为您设置头文件,这样您的语句就可以清楚地说明使用的是什么语言规则集。

标签: c++ c objective-c xcode objective-c++


【解决方案1】:

我假设你只是 #include/#importing 这个来自 .mm 文件的标头。

默认结构字段值是 C++11 的一个新特性。新项目中的 C++ 标准是否可能设置为 C++98?

我不能 100% 确定细节,但也许一些更复杂的默认值表达式只有在更新版本的 C++ 中才有可能。所以我建议你尝试在项目中更改C++标准版本,看看有没有效果。

【讨论】:

  • 谢谢! C++ 标准设置为 GNU 11。现在是 17,但同样的错误。此外,相同的代码在同一台机器上的另一个 Xcode 项目中编译。设置看似相同。
  • 在 OP 中添加了它。这是每次出现的第一个错误。我认为可以忽略缺失的类型。
  • 我认为它们不能被忽视。你确定这个文件不包含在 .m 文件中(甚至是间接的)吗?屏幕截图不是很好,因为它不包括错误回溯。从构建日志中复制粘贴更有帮助。
  • 终于解决了。这是关于项目中设置的 C++ 和 C (GNU11) 标准。它在干净和 Xcode 重新启动后工作(不确定是否真的需要重新启动)。此外,在文件检查器中,我确保将 .mm 文件类型设置为 Objective-C++ 源代码。
猜你喜欢
  • 2021-10-03
  • 2020-08-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多