Hello. I'm sure it's been asked before but I didn'...
# kotlin-native
d
Hello. I'm sure it's been asked before but I didn't manage to google anything and there is no slack history. I'm trying to do basic C interop with stdio.h and get this:
Copy code
$ cinterop -def stdio.def -o build/c_interop/stdio
KtFile: stdio.kt
$ konanc src/* build/c_interop/stdio-build/kotlin/stdio/* -library build/c_interop/stdio
KtFile: stdio.kt
KtFile: hello.kt
llvm-lto: error: Linking globals named 'kobjref:stdio.__sbuf.Companion': symbol multiply defined!
... kotlin stacktrace
Is it something I'm doing wrong or it's a known problem?
o
Dimitry, you unlikely need stdio in the first place, as platform.posix.* package already got everything you need, see for example https://github.com/JetBrains/kotlin-native/blob/master/samples/csvparser/src/main/kotlin/CsvParser.kt. To fix your particular problem, please rm -rf build, and link with .klib produced by interop code, not with the sources.
d
Thank you! I was only trying stdio as an exercise. To be fair, the exact steps are already mentioned in this tutorial https://kotlinlang.org/docs/tutorials/native/interop-with-c.html (although it feels a bit couter-intuitive that generated .kt file is treated not like other sources, may be it's worth mentioning in the tutorial)
For the record these commands worked fine:
Copy code
$ cinterop -def stdio.def -o build/c_interop/stdio
KtFile: stdio.kt
$ konanc src/* -library build/c_interop/stdio
KtFile: hello.kt
I.e. no need to mention
build/c_interop/stdio-build/kotlin/stdio/*
as a source location.