kotlin-nativecinterop

kotlin native cinterop add linkerOpts of source code


I add one header file and its source to my xcode project.

For example , AddToo.h

@interface AddTool : NSObject


-(NSString*) test:(NSString*) string;

@end

And the follow is source code

@implementation AddTool

-(NSString*) test:(NSString*) string {

    return string;
}

@end

test.def

language=Objective-C
headers=AddTool.h
package=com.tomliu

when I run the xcode project,

the error occurs

Undefined symbols for architecture arm64: "_OBJC_CLASS_$_AddTool", referenced from:

So should I build AddTool as static library first and add it to linkerOpts in .def file ?

Any other way to resolve this issue?

My kotlin version is 1.3.72

thanks


Solution

  • Note: This answer copies my answer on this question's duplicate located in the YouTrack-based Kotlin issue tracker(see here).
    As far as I know, one cannot make things work this way. Even though you can use a cinterop tool with this .def file as input, it will emit only bindings for a C library or Objective-C library/framework. Those bindings are like headers, they do not contain actual code, they should point onto an object file or a shared library. So yes, compiling a static library should help here.