【发布时间】: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++