I'm having problems with running C-interop on an O...
# kotlin-native
a
I'm having problems with running C-interop on an Objective C framework with a header that imports
Foundation
. The
cinterop
task fails with an exception:
Copy code
> Task :shared:cinteropObjektiveSSLIos FAILED
1 actionable task: 1 executed
Exception in thread "main" java.lang.Error: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.4.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:492:1: error: expected identifier or '('
	at org.jetbrains.kotlin.native.interop.indexer.UtilsKt.ensureNoCompileErrors(Utils.kt:152)
	at org.jetbrains.kotlin.native.interop.indexer.IndexerKt.indexDeclarations(Indexer.kt:1003)
	at org.jetbrains.kotlin.native.interop.indexer.IndexerKt.buildNativeIndexImpl(Indexer.kt:992)
	at org.jetbrains.kotlin.native.interop.indexer.NativeIndexKt.buildNativeIndex(NativeIndex.kt:91)
	at org.jetbrains.kotlin.native.interop.gen.jvm.MainKt.processCLib(main.kt:230)
	at org.jetbrains.kotlin.native.interop.gen.jvm.MainKt.interop(main.kt:46)
	at org.jetbrains.kotlin.cli.utilities.InteropCompilerKt.invokeInterop(InteropCompiler.kt:44)
	at org.jetbrains.kotlin.cli.utilities.MainKt.mainImpl(main.kt:19)
	at org.jetbrains.kotlin.cli.utilities.MainKt.main(main.kt:37)

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':shared:cinteropObjektiveSSLIos'.
> Process 'command '/Applications/IntelliJ IDEA <http://CE.app/Contents/jbr/Contents/Home/bin/java|CE.app/Contents/jbr/Contents/Home/bin/java>'' finished with non-zero exit value 1
Line 492 in NSObjCRuntime.h is:
Copy code
@class NSString, Protocol;
Is this a bug in Kotlin/Native or the
cinterop
tool? I can remove the import of
Foundation
to "fix" this bug but then it fails with
error: unknown type name 'NSData'
so I obviously need to keep it in there. Any workarounds?
It seems to work if I add
language = Objective-C
in the
.def
file. Is this documented anywhere? In that case I haven't found it 😅
🙌 1
👀 1
I found it used in an old GitHub issue, along with some other options for the .def file I have no idea what it does (but can guess) and have never seen documented anywhere. https://github.com/JetBrains/kotlin-native/issues/1841
a
Yep, this one seems to be missing from the documentation. Thank you for pointing it out! By default,
cinterop
always assume input files as plain C headers.