https://kotlinlang.org logo
Docs
Join the conversationJoin Slack
Channels
100daysofcode
100daysofkotlin
100daysofkotlin-2021
advent-of-code
aem
ai
alexa
algeria
algolialibraries
amsterdam
android
android-architecture
android-databinding
android-studio
androidgithubprojects
androidthings
androidx
androidx-xprocessing
anime
anko
announcements
apollo-kotlin
appintro
arabic
argentina
arkenv
arksemdevteam
armenia
arrow
arrow-contributors
arrow-meta
ass
atlanta
atm17
atrium
austin
australia
austria
awesome-kotlin
ballast
bangladesh
barcelona
bayarea
bazel
beepiz-libraries
belgium
berlin
big-data
books
boston
brazil
brikk
budapest
build
build-tools
bulgaria
bydgoszcz
cambodia
canada
carrat
carrat-dev
carrat-feed
chicago
chile
china
chucker
cincinnati-user-group
cli
clikt
cloudfoundry
cn
cobalt
code-coverage
codeforces
codemash-precompiler
codereview
codingame
codingconventions
coimbatore
collaborations
colombia
colorado
communities
competitive-programming
competitivecoding
compiler
compose
compose-android
compose-desktop
compose-hiring
compose-ios
compose-mp
compose-ui-showcase
compose-wear
compose-web
connect-audit-events
corda
cork
coroutines
couchbase
coursera
croatia
cryptography
cscenter-course-2016
cucumber-bdd
cyprus
czech
dagger
data2viz
databinding
datascience
dckotlin
debugging
decompose
decouple
denmark
deprecated
detekt
detekt-hint
dev-core
dfw
docs-revamped
dokka
domain-driven-design
doodle
dsl
dublin
dutch
eap
eclipse
ecuador
edinburgh
education
effective-kotlin
effectivekotlin
emacs
embedded-kotlin
estatik
event21-community-content
events
exposed
failgood
fb-internal-demo
feed
firebase
flow
fluid-libraries
forkhandles
forum
fosdem
fp-in-kotlin
framework-elide
freenode
french
fritz2
fuchsia
functional
funktionale
gamedev
ge-kotlin
general-advice
georgia
geospatial
german-lang
getting-started
github-workflows-kt
glance
godot-kotlin
google-io
gradle
graphic
graphkool
graphql
graphql-kotlin
graviton-browser
greece
grpc
gsoc
gui
hackathons
hacktoberfest
hamburg
hamkrest
helios
helsinki
hexagon
hibernate
hikari-cp
hire-me
hiring
hongkong
hoplite
http4k
hungary
hyderabad
image-processing
india
indonesia
inkremental
intellij
intellij-plugins
intellij-tricks
internships
introduce-yourself
io
ios
iran
israel
istanbulcoders
italian
jackson-kotlin
jadx
japanese
jasync-sql
java-to-kotlin-refactoring
javadevelopers
javafx
javalin
javascript
jdbi
jhipster-kotlin
jobsworldwide
jpa
jshdq
juul-libraries
jvm-ir-backend-feedback
jxadapter
k2-early-adopters
kaal
kafka
kakao
kalasim
kapt
karachi
karg
karlsruhe
kash_shell
kaskade
kbuild
kdbc
kgen-doc-tools
kgraphql
kinta
klaxon
klock
kloudformation
kmdc
kmm-español
kmongo
knbt
knote
koalaql
koans
kobalt
kobweb
kodein
kodex
kohesive
koin
koin-dev
komapper
kondor-json
kong
kontent
kontributors
korau
korean
korge
korim
korio
korlibs
korte
kotest
kotest-contributors
kotless
kotlick
kotlin-asia
kotlin-beam
kotlin-by-example
kotlin-csv
kotlin-data-storage
kotlin-foundation
kotlin-fuel
kotlin-in-action
kotlin-inject
kotlin-latam
kotlin-logging
kotlin-multiplatform-contest
kotlin-mumbai
kotlin-native
kotlin-pakistan
kotlin-plugin
kotlin-pune
kotlin-roadmap
kotlin-samples
kotlin-sap
kotlin-serbia
kotlin-spark
kotlin-szeged
kotlin-website
kotlinacademy
kotlinbot
kotlinconf
kotlindl
kotlinforbeginners
kotlingforbeginners
kotlinlondon
kotlinmad
kotlinprogrammers
kotlinsu
kotlintest
kotlintest-devs
kotlintlv
kotlinultimatechallenge
kotlinx-datetime
kotlinx-files
kotlinx-html
kotrix
kotson
kovenant
kprompt
kraph
krawler
kroto-plus
ksp
ktcc
ktfmt
ktlint
ktor
ktp
kubed
kug-leads
kug-torino
kvision
kweb
lambdaworld_cadiz
lanark
language-evolution
language-proposals
latvia
leakcanary
leedskotlinusergroup
lets-have-fun
libgdx
libkgd
library-development
linkeddata
lithuania
london
losangeles
lottie
love
lychee
macedonia
machinelearningbawas
madrid
malaysia
mathematics
meetkotlin
memes
meta
metro-detroit
mexico
miami
micronaut
minnesota
minutest
mirror
mockk
moko
moldova
monsterpuzzle
montreal
moonbean
morocco
motionlayout
mpapt
mu
multiplatform
mumbai
munich
mvikotlin
mvrx
myndocs-oauth2-server
naming
navigation-architecture-component
nepal
new-mexico
new-zealand
newname
nigeria
nodejs
norway
npm-publish
nyc
oceania
ohio-kotlin-users
oldenburg
oolong
opensource
orbit-mvi
osgi
otpisani
package-search
pakistan
panamá
pattern-matching
pbandk
pdx
peru
philippines
phoenix
pinoy
pocketgitclient
polish
popkorn
portugal
practical-functional-programming
proguard
prozis-android-backup
pyhsikal
python
python-contributors
quasar
random
re
react
reaktive
realm
realworldkotlin
reductor
reduks
redux
redux-kotlin
refactoring-to-kotlin
reflect
refreshversions
reports
result
rethink
revolver
rhein-main
rocksdb
romania
room
rpi-pico
rsocket
russian
russian_feed
russian-kotlinasfirst
rx
rxjava
san-diego
science
scotland
scrcast
scrimage
script
scripting
seattle
serialization
server
sg-user-group
singapore
skia-wasm-interop-temp
skrape-it
slovak
snake
sofl-user-group
southafrica
spacemacs
spain
spanish
speaking
spek
spin
splitties
spotify-mobius
spring
spring-security
squarelibraries
stackoverflow
stacks
stayhungrystayfoolish
stdlib
stlouis
strife-discord-lib
strikt
students
stuttgart
sudan
swagger-gradle-codegen
swarm
sweden
swing
swiss-user-group
switzerland
talking-kotlin
tallinn
tampa
teamcity
tegal
tempe
tensorflow
terminal
test
testing
testtestest
texas
tgbotapi
thailand
tornadofx
touchlab-tools
training
tricity-kotlin-user-group
trójmiasto
truth
tunisia
turkey
turkiye
twitter-feed
uae
udacityindia
uk
ukrainian
uniflow
unkonf
uruguay
utah
uuid
vancouver
vankotlin
vertx
videos
vienna
vietnam
vim
vkug
vuejs
web-mpp
webassembly
webrtc
wimix_sentry
wwdc
zircon
Powered by Linen
kotlin-native
  • h

    hfhbd

    09/05/2022, 1:01 PM
    Does anybody know what these error messages mean?
    w: Linking two modules of different data layouts: '/var/folders/8j/m605_xwx6s93xxf3tjfbkqlm0000gn/T/native4890200288988106563/cstubs.bc' is 'e-m:o-p:32:32-Fi8-i64:64-a:0:32-n32-S128' whereas 'out' is 'e-m:o-p:32:32-i64:64-i128:128-n32:64-S128'
    
    w: Linking two modules of different target triples: /var/folders/8j/m605_xwx6s93xxf3tjfbkqlm0000gn/T/native4890200288988106563/cstubs.bc' is 'thumbv7k-apple-watchos5.0.0' whereas 'out' is 'aarch64_32-apple-watchos5.0.0'
    Kotlin 1.7.20-Beta with macOS 13 (22A5331f) and Xcode 14.0 beta 6 (14A5294g)
    l
    • 2
    • 1
  • d

    darkmoon_uk

    09/07/2022, 12:49 PM
    What's the most efficient way to convert a platform
    float
    representation to a Kotlin
    ByteArray
    ?
    e
    • 2
    • 2
  • d

    darkmoon_uk

    09/07/2022, 12:50 PM
    I would prefer to mutate the same allocated
    ByteArray
    since I need to do this very often (preparing data for a shader).
  • a

    Adam Cooper

    09/07/2022, 9:30 PM
    Can someone please describe to me, or link to some detailed documentation, about how
    usePinned
    works in terms of C code? I am wondering why it is necessary, or perhaps if I am misusing it. If I am misusing it, then I would like to know what situations it should be used in. The way I have used it is similar to this:
    // declare a 256 byte array to pass to a C function as an output parameter
    UByteArray(SHA256_DIGEST_LENGTH).usePinned { signatureBuf ->
        c_func(signatureBuf.addressOf(0))
    }
    My understanding of the equivalent of this in C:
    unsigned char signatureBuf[SHA256_DIGEST_LENGTH];
    c_func(signatureBuf);
    c_func
    computes some value and stores it in the address provided by its parameter. This is a simplistic example and obv not good code. Just want to show my understanding of it.
    l
    e
    • 3
    • 25
  • a

    Adam Cooper

    09/08/2022, 12:28 AM
    When I attempt to run a test (CTRL+Shift+F10 in the test file), it runs just fine. But if I try to run with the debugger using the same configuration, the debugging window says "Test events were not received." Any advice on creating debuggable test configurations?
  • z

    zt

    09/09/2022, 3:38 AM
    I'm getting
    e: Could not find 'main' in '<root>' package.
    when trying to build either of the modules in my project. I've set up the gradle config like this
    linuxX64("native") {
        binaries {
            executable("prism")
        }
    }
    l
    a
    • 3
    • 14
  • p

    Paddy O'Brien

    09/14/2022, 8:11 PM
    Is there a way to disallow certain values used for the
    swift_name
    attribute when generating the Objective-C header? Upgrading to Apollo 3 and Codegen is now resulting in a scalar whose name is
    URL
    which of course is resulting in name conflicts when importing the framework into swift, Been bitten by this before, just wondering if theres a way that doesn’t involve changing swift code to accommodate changes in the Kotlin env
  • p

    Paddy O'Brien

    09/14/2022, 8:15 PM
    Alternatively, if there is a way to change the generated scalar name created during apollo code gen that’d also work
    b
    • 2
    • 21
  • k

    kevin.cianfarini

    09/16/2022, 8:36 PM
    Do Kotlin value types get “packed” when used in arrays? One of the main goals of Valhalla on the JVM is the following.
    Arrays of value types should be packed, without indirections, as arrays of primitives are now.
    Since Kotlin has separate, specialized, types for each primitive value how does this bode for value classes on Native? I imagine that
    Array<MyValueClass>
    would be boxed unless the compiler/runtime were doing some magic I’m unaware of.
    m
    • 2
    • 7
  • a

    Adam Cooper

    09/17/2022, 6:23 AM
    I'm having trouble getting a native program to link on certain distros. On my host machine, I'm running Manjaro, which keeps system libs in
    /usr/lib
    and
    /usr/include
    . My program is able to build just fine on this distro. I'm trying to build on Ubuntu, which uses
    {/usr/lib,/usr/include}/x86_64-linux-gnu
    . I have my compiler options defined in a .def:
    compilerOpts.linux = -I/usr/include -I/usr/include/x86_64-linux-gnu
    linkerOpts.linux = -L /usr/lib -L/usr/lib/x86_64-linux-gnu -lpthread -lssl -lcrypto
    My executable is defined in
    build.gradle.kts
    as follows:
    binaries {
                executable {
                    // Use system C libraries
                    val sysRoot = "/"
                    val libgccRoot = File("/lib/gcc/x86_64-linux-gnu/").takeIf { it.exists() }
                        ?: File("/lib/gcc/x86_64-pc-linux-gnu/")
                    // Use the most recent GCC available on the host
                    val libgccPath = file("${libgccRoot.absolutePath}/${libgccRoot.list()!!.last()}")
                    val overriddenProperties =
                        "targetSysRoot.linux_x64=$sysRoot;libGcc.linux_x64=$libgccPath"
                    val compilerArgs = "-Xoverride-konan-properties=$overriddenProperties"
                    this.freeCompilerArgs += listOf(compilerArgs)
                    this.entryPoint = "opstopus.deploptopus.main"
                    this@binaries.findTest("debug")?.let { it.freeCompilerArgs += listOf(compilerArgs) }
                }
            }
    On Ubuntu, I consistently get this error:
    /root/.konan/dependencies/x86_64-unknown-linux-gnu-gcc-8.3.0-glibc-2.19-kernel-4.9-2/x86_64-unknown-linux-gnu/bin/ld.gold: error: cannot open //usr/lib/crt1.o: No such file or directory
    /root/.konan/dependencies/x86_64-unknown-linux-gnu-gcc-8.3.0-glibc-2.19-kernel-4.9-2/x86_64-unknown-linux-gnu/bin/ld.gold: error: cannot open //usr/lib/crti.o: No such file or directory
    /root/.konan/dependencies/x86_64-unknown-linux-gnu-gcc-8.3.0-glibc-2.19-kernel-4.9-2/x86_64-unknown-linux-gnu/bin/ld.gold: error: cannot open //usr/lib/crtn.o: No such file or directory
    I confirmed that all 3 of these object files are in
    /usr/lib/x86_64-linux-gnu
    on Ubuntu. Why is it only searching in
    /usr/lib
    ?
    • 1
    • 1
  • j

    Jonas TM

    09/17/2022, 10:28 AM
    [Are context-receivers available in Kotlin/Native?] 🧵
    s
    r
    s
    • 4
    • 8
  • j

    Jeff Lockhart

    09/18/2022, 12:37 AM
    The docs say about converting Kotlin strings to C strings:
    To get the pointer,
    .cstr
    should be allocated in native memory, e.g.
    val cString = kotlinString.cstr.getPointer(nativeHeap)
    But
    getPointer()
    accepts an
    AutofreeScope
    parameter, which
    nativeHeap
    doesn't fulfill. Seems like it should be accepting a
    NativePlacement
    instead. (Maybe it used to?) Is there a more concise/idiomatic way to copy a Kotlin string to the native heap than something like this?
    val string = "my kotlin string"
    val bytes = string.encodeToByteArray()
    val cPtr = nativeHeap.allocArray<ByteVar>(bytes.size + 1)
    bytes.usePinned {
        memcpy(cPtr, it.addressOf(0), bytes.size.convert())
    }
    n
    s
    • 3
    • 10
  • n

    napperley

    09/19/2022, 1:35 AM
    Are the linking times going to be shorter with the Kotlin 1.7.20 release?
    p
    l
    e
    • 4
    • 9
  • j

    Jeff Lockhart

    09/21/2022, 1:26 AM
    Is it possible to get a reference to a lambda as a C pointer (
    CValuesRef<*>
    )? My API requires passing an arbitrary Kotlin lambda to a C library as a C function pointer. My understanding is that
    staticCFunction()
    would not be able to capture the lambda to call inside it:
    staticCFunction { ~lambda()~ }
    . I am able to have a context passed to the C Function as a
    COpaquePointer
    though. I could have the lambda passed as this context parameter, if there would be a way to get a reference to it as a C pointer.
    m
    • 2
    • 5
  • m

    martmists

    09/21/2022, 3:11 PM
    I noticed in the docs that threads aren't supported in kotlin/native; Is there an example on background tasks that can be started once and stopped once, and keep updating an array for the entire duration they're active for?
    t
    r
    +3
    • 6
    • 8
  • j

    Jeff Lockhart

    09/22/2022, 9:03 PM
    Is array index access
    []
    only available for
    CPointer<ByteVar>
    ? The docs seem to imply it should be possible for any
    CPointer<T>
    , but I only see the extension available for
    CPointer<ByteVar>
    (the docs show
    CPointer<BytePtr>
    in the example code). Do I have to
    reinterpret<ByteVar>()
    in order to iterate an array of a different pointer type?
    l
    • 2
    • 3
  • p

    Phạm Nhật

    09/23/2022, 6:55 AM
    Hi everyone. About this discussed thread for building multi-pods in multi-module projects world, is this limitation currently resolved or any workarounds available? https://kotlinlang.slack.com/archives/C3SGXARS6/p1631617605196000
    k
    • 2
    • 1
  • r

    Rihards

    09/26/2022, 10:37 AM
    Hi! Some help would be much appreciated on working with recycler view. I need to display data that I receive from the API in the horizontal recycler view. Each adapter item contains two TextViews and one ImageView, so the size of the view can vary for each data item. The issue is that I need to adjust all adapter item heights to the item that has the biggest height, but I can’t really find a way to do that since the item is not displayed in the screen till I scroll to it. Also, when I check some heights in
    onBindViewHolder
    they are zero.
    f
    • 2
    • 1
  • a

    Alexandre Brown

    09/27/2022, 2:10 PM
    Hello, I'm wonder how can I have something like Java JNI but for Kotlin? How do I generate a c/c++ header from Kotlin code? I have a JVM project (not multiplatform) where I would like to create a small Kotlin class to genenrate the c++ header then I will write C++ code to fulfill my needs. Is that doable?
    h
    b
    • 3
    • 12
  • k

    Krystian

    09/28/2022, 9:26 PM
    Hi. I'm doing a binding to a C game framework library and I'm manually tweaking some of the funcs. One function requires: const void *value (value is a parameter) Would I just need a CPointer for this? The generated binding shows that for the value parameter it would accept CValuesRef<*>?
    l
    • 2
    • 6
  • p

    Pablo

    09/29/2022, 11:48 AM
    Hi, which is the best and recommended way to program user interfaces for kotlin native for windows/linux? I recently disscovered compose multiplatform, but it seems to require a JVM installed, so it's not what I'm searching for. I'm interested in learning how to develop native applications for windows/linux not dependant of a JVM.
    t
    l
    +3
    • 6
    • 14
  • s

    spierce7

    09/29/2022, 3:27 PM
    Is there any way to easily access Kotlin native libraries via jni in a JVM application?
  • s

    spierce7

    09/29/2022, 3:27 PM
    I feel like I remember reading about a bridge or something years ago
  • j

    Jeff Lockhart

    09/30/2022, 2:08 AM
    Does anyone know if there's a way to link a cinterop dynamic .so library from a relative path within the project? This workaround seems to only work for static libraries.
    t
    d
    u
    • 4
    • 4
  • r

    ribesg

    09/30/2022, 8:53 AM
    Is
    VARIABLE_IN_SINGLETON_WITHOUT_THREAD_LOCAL
    still meaningful with the NMM or not?
  • k

    Krystian

    10/01/2022, 6:00 PM
    Is there a known issue with cinterop having problems converting macros with custom types? I'm trying to create a binding for C game framework library Raylib and it seems that custom defined colors of type struct Color holding unsigned char are not being converted over to Kotlin?
    a
    n
    • 3
    • 5
  • t

    Trevor Stone

    10/03/2022, 9:03 PM
    But to avoid needing to do that, you need to sign the app as well as notarize it
    r
    d
    k
    • 4
    • 5
  • k

    Katarzyna

    10/06/2022, 8:31 AM
    Dear Kotlin-native lovers, I am the manager of the self-publishing house. We are connected mainly with Kotlin. Our expert on this topic is Marcin Moskała. You could probably know him from conferences, workshops, and books: Kotlin Coroutines, Effective Kotlin, and Android Development with Kotlin. https://leanpub.com/u/mmoskala He is currently working on the book series Kotlin for Developers. It will contain 3 books: 1. Kotlin Essentials (in reviewing process) 2. Functional Kotlin (finished) 3. Advanced Kotlin (in draft) In the previous book - Functional Kotlin, Marcin decided to add a special chapter concerning the Arrow topic. The cooperation was really awesome. You are the experts on Kotlin/Native during many conferences and publications that is why we would like to encourage you to write a special chapter that will be published in Advanced Kotlin book about January 2023. What do you think? If you are interested let me know, please here in DM or contact via kasia@kt.academy. Regards:)
  • k

    Krystian

    10/08/2022, 10:41 AM
    I don't know if this fits this channel more or getting-started... I'm making a Raylib game framework binding to Kotlin Native and I'm trying to do a small Bunnymark benchmark to see how many bunnies (textures) can be spawned until the game hits 30FPS. Currently I'm hitting about 12.6k bunnies at 30/29fps (which is considerably lower than most languages e.g. Go hit 355500) and I'm unsure if there's anyway I can optimise the collections in native to squeeze all the juice possible? https://gist.github.com/Its-Kenta/5a42cb025281f252c87a987a184b69c7 any tips or code snippets on how to improve this would help me out a little.
    n
    d
    • 3
    • 4
  • j

    Jeff Lockhart

    10/11/2022, 6:19 PM
    I've noticed a difference in behavior between Linux and Windows with throwing an exception in a
    staticCFunction
    called from C code. On Windows, the exception is propagated and I can catch it in Kotlin with a try/catch surrounding the call to the C code that calls the
    staticCFunction
    . But on Linux, this exception is instead caught by the underlying C code and returned in the error code from the C function as an "unknown C++ exception". I'm trying to determine if this difference in behavior is due to Kotlin/Native, the C library, or possibly the GCC/MinGW compilers. I'd like to have access to the original exception to keep the behavior consistent between the two platforms. Is there a difference between the way Kotlin/Native exceptions behave on Windows vs Linux?
    • 1
    • 1
Powered by Linen
Title
j

Jeff Lockhart

10/11/2022, 6:19 PM
I've noticed a difference in behavior between Linux and Windows with throwing an exception in a
staticCFunction
called from C code. On Windows, the exception is propagated and I can catch it in Kotlin with a try/catch surrounding the call to the C code that calls the
staticCFunction
. But on Linux, this exception is instead caught by the underlying C code and returned in the error code from the C function as an "unknown C++ exception". I'm trying to determine if this difference in behavior is due to Kotlin/Native, the C library, or possibly the GCC/MinGW compilers. I'd like to have access to the original exception to keep the behavior consistent between the two platforms. Is there a difference between the way Kotlin/Native exceptions behave on Windows vs Linux?
I suppose as a workaround, I could perform the try/catch within the
staticCFunction
and save a global reference to a caught exception from within the
staticCFunction
to then access from outside the call if the "unknown C++ exception" error is encountered.
View count: 12