HomeiOS Developmentios - xcode 14.2 Error when Calling Objc Technique from C++

ios – xcode 14.2 Error when Calling Objc Technique from C++


I’m utilizing xcode 14.2 model. An error happens whereas creating an app utilizing Goal-C and c++.
Calling a c++ operate from objective-c is ok. However after I name the objective-c operate from c++, an error happens.

I modified the extension to ‘.mm’ after seeing an article saying that the ‘.m’ extension needs to be modified to ‘.mm’ with the intention to use ‘objective-c’ and ‘c++’ collectively.

OBJC

///objcSum.h

#ifndef objcSum_h
#outline objcSum_h

#import <Basis/Basis.h>
#import "mycpp.hpp"


@interface TDWObject : NSObject

-(NSInteger)addNum:(NSInteger)lhs second:(NSInteger)rhs;
-(NSInteger)getNum;

@finish

int TDWObjcSum(int num1, int num2);

#endif /* objcSum_h */
///objcSum.mm

#import "objcSum.h"

@implementation TDWObject

-(NSInteger)addNum:(NSInteger)lhs second:(NSInteger)rhs
{
    return lhs + rhs;
}

-(NSInteger)getNum
{
    MySum mysum;
    NSInteger num = mysum.ObjcCall(10, 100);
    return num;
}

@finish

int TDWObjcSum(int num1, int num2)
{
    TDWObject* tdwObject = [[TDWObject alloc]init];
    int res = [tdwObject addNum:num1 second:num2];
    [tdwObject release];
    return res;
}

C++

//myCpp.h

#ifdef __cplusplus
extern "C" {
#endif

int TDWCppSum(int a, int b);

#ifdef __cplusplus
}

class MySum {
public:
    int sum(int lhs, int rhs);
    int ObjcCall(int num1, int num2);
    
};

#endif
#embrace "mycpp.hpp"
#embrace "objcSum.h"


int MySum::sum(int lhs, int rhs){
    return lhs + rhs;
}

int TDWCppSum(int a, int b) {
    MySum mysum;
    return mysum.sum(a, b);
//    return MySum{}.sum(a, b);
}

int MySum::ObjcCall(int num1, int num2)
{
    int res = TDWObjcSum(num1, num2);
    return res;
}

Code that calls the precise operate

//AppDelegate.mm

TDWObject* tdwObjct = [[TDWObject alloc]init];
          int res = [tdwObjct getNum];
          [tdwObjct release];

However after I construct it I get an error.

Error Message


Exhibiting Current Messages
CompileC /Customers/sinjeong-won/Library/Developer/Xcode/DerivedData/Runner-fiwvkgeptrgkurarntkwsxtdzbqb/Construct/Intermediates.noindex/Runner.construct/Debug-iphoneos/Runner.construct/Objects-normal/arm64/mycpp.o /Customers/sinjeong-won/Desktop/elfscoreprint_mobile_20230220/ios/Runner/mycpp.cpp regular arm64 c++ com.apple.compilers.llvm.clang.1_0.compiler (in goal 'Runner' from undertaking 'Runner')
    cd /Customers/sinjeong-won/Desktop/elfscoreprint_mobile_20230220/ios
    export LANG=en_US.US-ASCII
    /Functions/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -x c++ -target arm64-apple-ios15.3 -fmessage-length=0 -fdiagnostics-show-note-include-stack -fmacro-backtrace-limit=0 -std=gnu++11 -stdlib=libc++ -fmodules -gmodules -fmodules-cache-path=/Customers/sinjeong-won/Library/Developer/Xcode/DerivedData/ModuleCache.noindex -fmodules-prune-interval=86400 -fmodules-prune-after=345600 -fbuild-session-file=/Customers/sinjeong-won/Library/Developer/Xcode/DerivedData/ModuleCache.noindex/Session.modulevalidation -fmodules-validate-once-per-build-session -Wnon-modular-include-in-framework-module -Werror=non-modular-include-in-framework-module -Wno-trigraphs -fpascal-strings -O0 -fno-common -Wno-missing-field-initializers -Wno-missing-prototypes -Werror=return-type -Wunreachable-code -Werror=deprecated-objc-isa-usage -Werror=objc-root-class -Wno-non-virtual-dtor -Wno-overloaded-virtual -Wno-exit-time-destructors -Wno-missing-braces -Wparentheses -Wswitch -Wunused-function -Wno-unused-label -Wno-unused-parameter -Wunused-variable -Wunused-value -Wempty-body -Wuninitialized -Wconditional-uninitialized -Wno-unknown-pragmas -Wno-shadow -Wno-four-char-constants -Wno-conversion -Wconstant-conversion -Wint-conversion -Wbool-conversion -Wenum-conversion -Wno-float-conversion -Wnon-literal-null-conversion -Wobjc-literal-conversion -Wshorten-64-to-32 -Wno-newline-eof -Wno-c++11-extensions -DDEBUG=1 -DCOCOAPODS=1 -isysroot /Functions/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS15.4.sdk -fstrict-aliasing -Wdeprecated-declarations -Winvalid-offsetof -g -fvisibility-inlines-hidden -Wno-sign-conversion -Winfinite-recursion -Wmove -Wcomma -Wblock-capture-autoreleasing -Wstrict-prototypes -Wrange-loop-analysis -Wno-semicolon-before-method-body -index-store-path /Customers/sinjeong-won/Library/Developer/Xcode/DerivedData/Runner-fiwvkgeptrgkurarntkwsxtdzbqb/Index/DataStore -iquote /Customers/sinjeong-won/Library/Developer/Xcode/DerivedData/Runner-fiwvkgeptrgkurarntkwsxtdzbqb/Construct/Intermediates.noindex/Runner.construct/Debug-iphoneos/Runner.construct/Runner-generated-files.hmap -I/Customers/sinjeong-won/Library/Developer/Xcode/DerivedData/Runner-fiwvkgeptrgkurarntkwsxtdzbqb/Construct/Intermediates.noindex/Runner.construct/Debug-iphoneos/Runner.construct/Runner-own-target-headers.hmap -I/Customers/sinjeong-won/Library/Developer/Xcode/DerivedData/Runner-fiwvkgeptrgkurarntkwsxtdzbqb/Construct/Intermediates.noindex/Runner.construct/Debug-iphoneos/Runner.construct/Runner-all-non-framework-target-headers.hmap -ivfsoverlay /Customers/sinjeong-won/Library/Developer/Xcode/DerivedData/Runner-fiwvkgeptrgkurarntkwsxtdzbqb/Construct/Intermediates.noindex/Runner.construct/Debug-iphoneos/Runner.construct/all-product-headers.yaml -iquote /Customers/sinjeong-won/Library/Developer/Xcode/DerivedData/Runner-fiwvkgeptrgkurarntkwsxtdzbqb/Construct/Intermediates.noindex/Runner.construct/Debug-iphoneos/Runner.construct/Runner-project-headers.hmap -I/Customers/sinjeong-won/Library/Developer/Xcode/DerivedData/Runner-fiwvkgeptrgkurarntkwsxtdzbqb/Construct/Merchandise/Debug-iphoneos/embrace -I/Customers/sinjeong-won/Library/Developer/Xcode/DerivedData/Runner-fiwvkgeptrgkurarntkwsxtdzbqb/Construct/Merchandise/Debug-iphoneos/device_info_plus/device_info_plus.framework/Headers -I/Customers/sinjeong-won/Library/Developer/Xcode/DerivedData/Runner-fiwvkgeptrgkurarntkwsxtdzbqb/Construct/Merchandise/Debug-iphoneos/path_provider_ios/path_provider_ios.framework/Headers -I/Customers/sinjeong-won/Library/Developer/Xcode/DerivedData/Runner-fiwvkgeptrgkurarntkwsxtdzbqb/Construct/Merchandise/Debug-iphoneos/pdfx/pdfx.framework/Headers -I/Customers/sinjeong-won/Library/Developer/Xcode/DerivedData/Runner-fiwvkgeptrgkurarntkwsxtdzbqb/Construct/Merchandise/Debug-iphoneos/printing/printing.framework/Headers -I/Customers/sinjeong-won/Library/Developer/Xcode/DerivedData/Runner-fiwvkgeptrgkurarntkwsxtdzbqb/Construct/Merchandise/Debug-iphoneos/uni_links/uni_links.framework/Headers -I/Customers/sinjeong-won/Library/Developer/Xcode/DerivedData/Runner-fiwvkgeptrgkurarntkwsxtdzbqb/Construct/Intermediates.noindex/Runner.construct/Debug-iphoneos/Runner.construct/DerivedSources-normal/arm64 -I/Customers/sinjeong-won/Library/Developer/Xcode/DerivedData/Runner-fiwvkgeptrgkurarntkwsxtdzbqb/Construct/Intermediates.noindex/Runner.construct/Debug-iphoneos/Runner.construct/DerivedSources/arm64 -I/Customers/sinjeong-won/Library/Developer/Xcode/DerivedData/Runner-fiwvkgeptrgkurarntkwsxtdzbqb/Construct/Intermediates.noindex/Runner.construct/Debug-iphoneos/Runner.construct/DerivedSources -F/Customers/sinjeong-won/Library/Developer/Xcode/DerivedData/Runner-fiwvkgeptrgkurarntkwsxtdzbqb/Construct/Merchandise/Debug-iphoneos -F/Customers/sinjeong-won/Library/Developer/Xcode/DerivedData/Runner-fiwvkgeptrgkurarntkwsxtdzbqb/Construct/Merchandise/Debug-iphoneos/device_info_plus -F/Customers/sinjeong-won/Library/Developer/Xcode/DerivedData/Runner-fiwvkgeptrgkurarntkwsxtdzbqb/Construct/Merchandise/Debug-iphoneos/path_provider_ios -F/Customers/sinjeong-won/Library/Developer/Xcode/DerivedData/Runner-fiwvkgeptrgkurarntkwsxtdzbqb/Construct/Merchandise/Debug-iphoneos/pdfx -F/Customers/sinjeong-won/Library/Developer/Xcode/DerivedData/Runner-fiwvkgeptrgkurarntkwsxtdzbqb/Construct/Merchandise/Debug-iphoneos/printing -F/Customers/sinjeong-won/Library/Developer/Xcode/DerivedData/Runner-fiwvkgeptrgkurarntkwsxtdzbqb/Construct/Merchandise/Debug-iphoneos/uni_links -MMD -MT dependencies -MF /Customers/sinjeong-won/Library/Developer/Xcode/DerivedData/Runner-fiwvkgeptrgkurarntkwsxtdzbqb/Construct/Intermediates.noindex/Runner.construct/Debug-iphoneos/Runner.construct/Objects-normal/arm64/mycpp.d --serialize-diagnostics /Customers/sinjeong-won/Library/Developer/Xcode/DerivedData/Runner-fiwvkgeptrgkurarntkwsxtdzbqb/Construct/Intermediates.noindex/Runner.construct/Debug-iphoneos/Runner.construct/Objects-normal/arm64/mycpp.dia -c /Customers/sinjeong-won/Desktop/elfscoreprint_mobile_20230220/ios/Runner/mycpp.cpp -o /Customers/sinjeong-won/Library/Developer/Xcode/DerivedData/Runner-fiwvkgeptrgkurarntkwsxtdzbqb/Construct/Intermediates.noindex/Runner.construct/Debug-iphoneos/Runner.construct/Objects-normal/arm64/mycpp.o -index-unit-output-path /Runner.construct/Debug-iphoneos/Runner.construct/Objects-normal/arm64/mycpp.o

In file included from /Customers/sinjeong-won/Desktop/elfscoreprint_mobile_20230220/ios/Runner/mycpp.cpp:9:
In file included from /Customers/sinjeong-won/Desktop/elfscoreprint_mobile_20230220/ios/Runner/objcSum.h:11:
In file included from /Functions/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS15.4.sdk/System/Library/Frameworks/Basis.framework/Headers/Basis.h:8:
/Functions/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS15.4.sdk/System/Library/Frameworks/Basis.framework/Headers/NSObjCRuntime.h:523:1: error: anticipated unqualified-id
@class NSString, Protocol;
^
/Functions/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS15.4.sdk/System/Library/Frameworks/Basis.framework/Headers/NSObjCRuntime.h:525:9: error: unknown sort title 'NSString'
typedef NSString * NSExceptionName NS_TYPED_EXTENSIBLE_ENUM;
        ^
/Functions/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS15.4.sdk/System/Library/Frameworks/Basis.framework/Headers/NSObjCRuntime.h:526:9: error: unknown sort title 'NSString'
typedef NSString * NSRunLoopMode NS_TYPED_EXTENSIBLE_ENUM;
        ^
/Functions/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS15.4.sdk/System/Library/Frameworks/Basis.framework/Headers/NSObjCRuntime.h:528:19: error: unknown sort title 'NSString'
FOUNDATION_EXPORT NSString *NSStringFromSelector(SEL aSelector);
                  ^
/Functions/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS15.4.sdk/System/Library/Frameworks/Basis.framework/Headers/NSObjCRuntime.h:529:44: error: unknown sort title 'NSString'
FOUNDATION_EXPORT SEL NSSelectorFromString(NSString *aSelectorName);
                                           ^
/Functions/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS15.4.sdk/System/Library/Frameworks/Basis.framework/Headers/NSObjCRuntime.h:531:19: error: unknown sort title 'NSString'
FOUNDATION_EXPORT NSString *NSStringFromClass(Class aClass);
                  ^
/Functions/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS15.4.sdk/System/Library/Frameworks/Basis.framework/Headers/NSObjCRuntime.h:532:53: error: unknown sort title 'NSString'
FOUNDATION_EXPORT Class _Nullable NSClassFromString(NSString *aClassName);
                                                    ^
/Functions/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS15.4.sdk/System/Library/Frameworks/Basis.framework/Headers/NSObjCRuntime.h:534:19: error: unknown sort title 'NSString'
FOUNDATION_EXPORT NSString *NSStringFromProtocol(Protocol *proto) API_AVAILABLE(macos(10.5), ios(2.0), watchos(2.0), tvos(9.0));
                  ^
/Functions/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS15.4.sdk/System/Library/Frameworks/Basis.framework/Headers/NSObjCRuntime.h:534:50: error: unknown sort title 'Protocol'
FOUNDATION_EXPORT NSString *NSStringFromProtocol(Protocol *proto) API_AVAILABLE(macos(10.5), ios(2.0), watchos(2.0), tvos(9.0));
                                                 ^
/Functions/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS15.4.sdk/System/Library/Frameworks/Basis.framework/Headers/NSObjCRuntime.h:535:19: error: unknown sort title 'Protocol'
FOUNDATION_EXPORT Protocol * _Nullable NSProtocolFromString(NSString *namestr) API_AVAILABLE(macos(10.5), ios(2.0), watchos(2.0), tvos(9.0));
                  ^
/Functions/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS15.4.sdk/System/Library/Frameworks/Basis.framework/Headers/NSObjCRuntime.h:535:61: error: unknown sort title 'NSString'
FOUNDATION_EXPORT Protocol * _Nullable NSProtocolFromString(NSString *namestr) API_AVAILABLE(macos(10.5), ios(2.0), watchos(2.0), tvos(9.0));
                                                            ^
/Functions/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS15.4.sdk/System/Library/Frameworks/Basis.framework/Headers/NSObjCRuntime.h:539:30: error: unknown sort title 'NSString'
FOUNDATION_EXPORT void NSLog(NSString *format, ...) NS_FORMAT_FUNCTION(1,2) NS_NO_TAIL_CALL;
                             ^
/Functions/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS15.4.sdk/System/Library/Frameworks/Basis.framework/Headers/NSObjCRuntime.h:539:53: error: format argument not an NSString
FOUNDATION_EXPORT void NSLog(NSString *format, ...) NS_FORMAT_FUNCTION(1,2) NS_NO_TAIL_CALL;
                             ~~~~~~~~~~~~~~~~       ^                  ~
/Functions/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS15.4.sdk/System/Library/Frameworks/Basis.framework/Headers/NSObjCRuntime.h:94:49: notice: expanded from macro 'NS_FORMAT_FUNCTION'
        #outline NS_FORMAT_FUNCTION(F,A) __attribute__((format(__NSString__, F, A)))
                                                       ^                    ~
/Functions/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS15.4.sdk/System/Library/Frameworks/Basis.framework/Headers/NSObjCRuntime.h:540:31: error: unknown sort title 'NSString'
FOUNDATION_EXPORT void NSLogv(NSString *format, va_list args) NS_FORMAT_FUNCTION(1,0) NS_NO_TAIL_CALL;
                              ^
/Functions/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS15.4.sdk/System/Library/Frameworks/Basis.framework/Headers/NSObjCRuntime.h:540:63: error: format argument not an NSString
FOUNDATION_EXPORT void NSLogv(NSString *format, va_list args) NS_FORMAT_FUNCTION(1,0) NS_NO_TAIL_CALL;
                              ~~~~~~~~~~~~~~~~                ^                  ~
/Functions/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS15.4.sdk/System/Library/Frameworks/Basis.framework/Headers/NSObjCRuntime.h:94:49: notice: expanded from macro 'NS_FORMAT_FUNCTION'
        #outline NS_FORMAT_FUNCTION(F,A) __attribute__((format(__NSString__, F, A)))
                                                       ^                    ~
In file included from /Customers/sinjeong-won/Desktop/elfscoreprint_mobile_20230220/ios/Runner/mycpp.cpp:9:
In file included from /Customers/sinjeong-won/Desktop/elfscoreprint_mobile_20230220/ios/Runner/objcSum.h:11:
In file included from /Functions/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS15.4.sdk/System/Library/Frameworks/Basis.framework/Headers/Basis.h:10:
In file included from /Functions/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS15.4.sdk/System/Library/Frameworks/Basis.framework/Headers/NSArray.h:5:
In file included from /Functions/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS15.4.sdk/System/Library/Frameworks/Basis.framework/Headers/NSObject.h:8:
/Functions/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS15.4.sdk/System/Library/Frameworks/Basis.framework/Headers/NSZone.h:9:1: error: anticipated unqualified-id
@class NSString;
^
/Functions/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS15.4.sdk/System/Library/Frameworks/Basis.framework/Headers/NSZone.h:19:63: error: unknown sort title 'NSString'
FOUNDATION_EXPORT void NSSetZoneName(NSZone * _Nullable zone, NSString *title)NS_SWIFT_UNAVAILABLE("Zone-based reminiscence administration is unavailable");
                                                              ^
/Functions/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS15.4.sdk/System/Library/Frameworks/Basis.framework/Headers/NSZone.h:20:19: error: unknown sort title 'NSString'
FOUNDATION_EXPORT NSString *NSZoneName(NSZone * _Nullable zone) NS_SWIFT_UNAVAILABLE("Zone-based reminiscence administration is unavailable");
                  ^
In file included from /Customers/sinjeong-won/Desktop/elfscoreprint_mobile_20230220/ios/Runner/mycpp.cpp:9:
In file included from /Customers/sinjeong-won/Desktop/elfscoreprint_mobile_20230220/ios/Runner/objcSum.h:11:
In file included from /Functions/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS15.4.sdk/System/Library/Frameworks/Basis.framework/Headers/Basis.h:10:
In file included from /Functions/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS15.4.sdk/System/Library/Frameworks/Basis.framework/Headers/NSArray.h:5:
/Functions/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS15.4.sdk/System/Library/Frameworks/Basis.framework/Headers/NSObject.h:10:1: error: anticipated unqualified-id
@class NSInvocation, NSMethodSignature, NSCoder, NSString, NSEnumerator;
^
deadly error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments