NSBundle Redeclaration Error for Multiple Functions In Metal CPP

Hi I am trying to get started using Metal CPP after viewing the documentation and defining the constants below:

#ifndef MTL_PRIVATE_IMPLEMENTATION

    #define NS_PRIVATE_IMPLEMENTATION
    #define MTL_PRIVATE_IMPLEMENTATION
    //#define MTK_PRIVATE_IMPLEMENTATION
    #define CA_PRIVATE_IMPLEMENTATION

#endif

I commented out the MTK macro since it was not in the getting started video although it was in the fundamentals projects for metal cpp. I am defining this in a Objective C++ header along with including:

#import <Foundation/Foundation.hpp>

#import <Metal/Metal.hpp>

#import <QuartzCore/QuartzCore.hpp>

#import <MetalKit/MetalKit.h>

#import <simd/simd.h>

I get the error:

redeclaration of 'NSPOSIXErrorDomain' with a different type: 'const NSErrorDomain  _Nonnull __strong' (aka 'NSString *const __strong') vs 'const NS::ErrorDomain' (aka 'NS::String *const')

along with other errors similar to that one. These errors all seem to do with <Foundation/Foundation.h>. I can see that the NS prefix is being declared rather than the C++ version of NS:: but I am sure I implemented this correctly. I have a header set up in Objective C for this file along with things being @implementation rather than pure C++:

#pragma once



#include "../../../src/state/config.h"



#ifdef __PEN_IOS__

//#import <cassert>

#ifndef MTL_PRIVATE_IMPLEMENTATION

#define NS_PRIVATE_IMPLEMENTATION

#define MTL_PRIVATE_IMPLEMENTATION

//#define MTK_PRIVATE_IMPLEMENTATION

#define CA_PRIVATE_IMPLEMENTATION

#endif



#ifdef TARGET_IPHONE_SIMULATOR

//#import <UIKit/UIKit.h>

#elifdef TARGET_OS_IPHONE

//#import <UIKit/UIKit.hpp>

#elifdef TARGET_OS_IOS

//#import <UIKit/UIKit.hpp>

#elifdef TARGET_OS_MAC

//#import <AppKit/AppKit.hpp>

#endif

#import <Foundation/Foundation.hpp>

#import <Metal/Metal.hpp>

//#import <CoreFoundation/CoreFoundation.h>

#import <QuartzCore/QuartzCore.hpp>

#import <MetalKit/MetalKit.h>

#import <simd/simd.h>

#import "ios_cpp_objective_c_mapping.h"



@class IOSState;



@interface IOSState : NSObject



	@property MTK::View* iosMtkView;

    @property MTL::Device* iosDevice;

    @property MTL::CommandQueue* iosCommandQueue;

    @property MTL::RenderPipelineState* iosPipelineState;

    @property NS::Notification* iosLaunchNotification;

    @property MTL::ArgumentEncoder* iosArgEncoder;

    @property MTL::DepthStencilState* iosDepthStencilState;

    @property MTL::Texture* iosPixelBuffer;

    @property MTL::Buffer* iosUniformBuffer;

    @property MTL::Buffer* iosInstanceBuffer;

    @property MTL::RenderCommandEncoder* iosCommandEncoder;

    @property MTL::CommandBuffer* iosCommandBuffer;

    @property NS::AutoreleasePool* iosAutoReleasePool;

    @property dispatch_semaphore_t dispatchSemaphore;



+ (IOSState*) Get;

+ (void) Destroy;

@end

#endif

I include this file in multiple places although the headers should be able to be included more than once.

Also if you want to see the implementation it is at https://github.com/fentacoder/pen_engine in the ext/platforms/ios folder, any help is appreciated thank you.

The initial problem is fixed now that the Objective C way of Metal is being completely used instead of the C++ way, but now I get an error on the linking of the Objective C C++ mapping when calling Objective C functions from C++ files.

Accepted Answer

Okay so after updating the interface and changing the initialization of Metal it seems things build and link correctly.

NSBundle Redeclaration Error for Multiple Functions In Metal CPP
 
 
Q