Manoj Bisarahalli
Manoj Bisarahalli

Reputation: 91

Using C library functions in kotlin

I have been trying to follow this blog and I have run all the steps successfully but however when I run the last command

konanc $COMPILER_ARGS -target macbook src/main/kotlin/logogen.kt -library build/c_interop/png -linkerOpts "-L/usr/local/lib -lpng" -o build/bin/logogen

I get errors which say sqrt,pow,fopen,fclose are all unresolved

error: unresolved reference: sqrt

This is what is in my png.def file

headers = /usr/local/include/png.h stdio.h stdlib.h string.h math.h

Imported it in my logogen.kt file as

import png.*

Thank you!

Upvotes: 0

Views: 652

Answers (2)

Nikolay Igotti
Nikolay Igotti

Reputation: 598

compilerOpts = -lm in the .def file shall do the trick.

Upvotes: 1

Grzegorz Adam Hankiewicz
Grzegorz Adam Hankiewicz

Reputation: 7661

What are you replacing $COMPILER_ARGS with? Presumably you pass there the C libraries that define those C references and which are required by your program. For example, for the sqrt undefined reference you would add '-lm'. Same for anything else that the compiler tells you is missing.

Upvotes: 0

Related Questions