Is there a current guide to creating a Kotlin nati...
# kotlin-native
v
Is there a current guide to creating a Kotlin native library with gradle anywhere? https://kotlinlang.org/docs/reference/native/gradle_plugin.html makes reference to things like:
Copy code
components.main {
    // Compile the component into an executable and a Kotlin/Native library.
    outputKinds = [EXECUTABLE, KLIBRARY]
}
Which we all know doesn't work,
components.main
is completely invalid syntax. I tried creating an empty Kotlin/Native library using Intellij's new project wizard did not add anything like
outputKinds = KLIBRARY
.
a
This is an outdated plugin’s reference, please have a closer look at https://kotlinlang.org/docs/reference/mpp-build-native-binaries.html
v
Thanks @Artyom Degtyarev [JB], I think that worked. Though I've probably found more konanc bugs 🙂. I'm definitely doing things other people aren't doing!
👍 2
So the idea is that I replace
Copy code
binaries {
            executable("waveshare") {
                this.optimized = false
                entryPoint = "org.liamjd.pi.main"
            }
        }
With
Copy code
binaries {
            staticLib {
                this.optimized = false
            }
        }
a
Yes, this or
sharedLib
 , I suppose. Also, feel free to share your experience here, and file bugs at kotl.in/issue, Kotlin team is always interested in feedback.
v
OK, I'll raise another bug; the code can't compile at all. I suspect it's my heavy use of
UByteArray
which is already causing problems.
a
Answered on youtrack with a workaround: just add this dummy function somewhere in code
Copy code
fun exposeByteArray(): ByteArray =byteArrayOf(0x01, 0x00)
This should generate correct symbol for the library. Please give it a try, and if it work for you too I think we’ll be able to mark ticket correctly, and go to the https://youtrack.jetbrains.com/issue/KT-36878 for the upvote button 😄
v
Well, I have good news and I have bad news... Adding that dummy function seems to have helped; there are no errors in generating the header files. The project compiles on Linux. But I think I've found a new bug in the compiler/linker when creating a staticLib on a Windows 10 machine (perhaps only when my Windows user name contains a space) (perhaps only when my project is on a different drive from my Windows user profile). The error does not happen on my Ubuntu VM... I'll check to see if the bug has been reported already :)