# Kotlinc native compiler - How to import "kotlinx.cinterop" to use "memScoped"?

**URL:** <https://discuss.kotlinlang.org/t/kotlinc-native-compiler-how-to-import-kotlinx-cinterop-to-use-memscoped/25816>\
**Category:** Support\
**Created:** [October 16, 2022, 9:26pm UTC](https://discuss.kotlinlang.org/t/kotlinc-native-compiler-how-to-import-kotlinx-cinterop-to-use-memscoped/25816 "2022-10-16T21:26:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![umydwbp935](https://avatars.discourse-cdn.com/v4/letter/u/ed8c4c/32.png) [@umydwbp935](https://discuss.kotlinlang.org/u/umydwbp935)\
**Post date:** [October 16, 2022, 9:26pm UTC](https://discuss.kotlinlang.org/t/kotlinc-native-compiler-how-to-import-kotlinx-cinterop-to-use-memscoped/25816/1 "2022-10-16T21:26:32Z")

</div>

Hi there, I would like to write something like this:

```
val fileSize = memScoped {
	val statBuf = alloc<stat>()
	val error = stat("/", statBuf.ptr)
	statBuf.st_size
}

```

However, upon compilation I get:

unresolved reference: memScoped, unresolved reference: alloc (etc…)

Which libraries would I need to import in order to use C functions with Kotlin? Googling this problem provides a “libcurl” example which isn’t useful at all. It also instructs to create a “def” file and include a header in order to make use of a particular C library function. However, there is no information on how to use memscope.

I have created my own scripts in Kotlin in order to compile with kotlinc, and it includes all needed libraries for my project in a folder.

I would appreciate your help, meanwhile thanks for your time and patience.

---

<div class="post-metadata">

**Author:** ![arturdumchev](https://avatars.discourse-cdn.com/v4/letter/a/858c86/32.png) [@arturdumchev](https://discuss.kotlinlang.org/u/arturdumchev)\
**Post date:** [October 31, 2025, 9:42am UTC](https://discuss.kotlinlang.org/t/kotlinc-native-compiler-how-to-import-kotlinx-cinterop-to-use-memscoped/25816/2 "2025-10-31T09:42:52Z")

</div>

I had a similar issue. I fixed it by removing (reinstalling) the ~/.konan folder. I realized I needed to remove it when I noticed that some functions in the Kotlin/Native stdlib were missing, and the library path pointed to ~/.konan

 ![image](https://us1.discourse-cdn.com/flex019/uploads/kotlinlang/original/2X/8/832a72cc062c8a52615caf3527516111ab399a69.jpeg)
