I am trying to create a binding for `time.h` heade...
# kotlin-native
a
I am trying to create a binding for
time.h
header and the cinterop tool throws an exception, can someone help? time.def
Copy code
headers = /usr/include/time.h
compilerOpts = -std=c99
Copy code
Exception in thread "main" java.lang.Error: /usr/include/time.h:37:10: fatal error: 'bits/types/clock_t.h' file not found
	at org.jetbrains.kotlin.native.interop.indexer.UtilsKt.ensureNoCompileErrors(Utils.kt:137)
	at org.jetbrains.kotlin.native.interop.indexer.IndexerKt.indexDeclarations(Indexer.kt:902)
	at org.jetbrains.kotlin.native.interop.indexer.IndexerKt.buildNativeIndexImpl(Indexer.kt:892)
	at org.jetbrains.kotlin.native.interop.indexer.NativeIndexKt.buildNativeIndex(NativeIndex.kt:56)
	at org.jetbrains.kotlin.native.interop.gen.jvm.MainKt.processCLib(main.kt:284)
	at org.jetbrains.kotlin.native.interop.gen.jvm.MainKt.interop(main.kt:38)
	at org.jetbrains.kotlin.cli.utilities.InteropCompilerKt.invokeInterop(InteropCompiler.kt:100)
	at org.jetbrains.kotlin.cli.utilities.MainKt.main(main.kt:29)
Isn't there a way to automatically include all the
#include <>
inside the header file itself?
s
All the includes inside the header are automatically included. Your interop configuration is invalid. Declarations from
time.h
etc are already available from platform libraries without any additional configuration. You can try to add
import platform.posix.*
.
a
Oh thank you
How can a assign the address of
val x
to a variable (newbie question)
s
You can’t. Kotlin variable doesn’t have an address currently.
a
🤔
m
If
x
is Array -
x.toCValues().ptr
a
@msink How can I de-reference a CPointer<IntVar>?
Copy code
val int = malloc(4)?.reinterpret<IntVar>()
println(int?.rawValue)
m
like this:
Copy code
memScoped {
    val time = alloc<time_tVar>()
    time.value = v
    return localtime(time.ptr)!!
}