6

I'm trying to learn how Kotlin Native works with this tutorial from JetBrains: https://kotlinlang.org/docs/tutorials/native/interop-with-c.html

But these tutorials are only fro macOS and Linux. Sometimes i use a windows computer and i want to know how it works there.

How can i add the libcurl library in windows and how can i add it to the libcurl.def file?

It isn't explained anywhere.

5 Answers 5

3

You need to install MSYS2, then in MSYS2 console install libcurl:

$ pacman -S mingw-w64-x86_64-curl

See https://github.com/JetBrains/kotlin-native/pull/1499

2
3

A more detailed step-by-step explanation on how to use dynamically built libcurl (aka DLL) with Kotlin/Native.

https://jonnyzzz.com/blog/2018/10/29/kn-libcurl-windows/

2

I do not think it is covered somewhere right now. The idea is still the same, and you should be able to make it work. The first step is to download and build libcurl locally from https://curl.haxx.se/libcurl/. There are instructions and documentation on how to build it. I do recommend to pick the Windows own implementation for SSL.

Once you are done with building you will have both the includes and the library. Note, on Windows, you will always have a static library. Even if you build curl as a dynamic library (DLL), you will have a generated static library that you use for linking. DLL is easier to build and use. A true static library is better because you will have no dependencies in your Kotlin/Native program binary. At that point, the tutorial instructions should work.

2
  • Where should i place the static library file? In linux it is on the compiler libs path i think. Am i right? In addition, for linux and mac there are special linkerOpts arguments. What should i do for windows here? Oct 19, 2018 at 11:04
  • just include the path to the linkerOpts Dec 24, 2018 at 11:38
2

For Windows, if you need only basic HTTP communication, you can also try WinINet API which is a part of Windows and so no dependency is necessary. No hassle with the libcurl library.

See my example of how to use WinInet API with Kotlin MPP: https://github.com/localazy/kotlin-mpp-wininet

For macOS and Linux, instead of going through the hassle with libcurl manually, just use ktor clients: https://ktor.io/clients/index.html

-1

I'm studying Kotlin too and it took many hours until I realize how to handle def file, includes and static library.

I made an example of how to use static library (curl with gzip and SSL support compiled with mingw) on kotlin-native. This way you dont need to dll files to be supplied with your app

https://github.com/carlosrafp/Libcurl-Kotlin-Native-standalone

On libcurl.def file you can see:

headers = curl/curl.h   // path to curl header
libraryPaths = src/nativeInterop/cinterop  // path to your static library
staticLibraries = libcurl.a // the static library
linkerOpts.mingw = -lws2_32 -lwldap32 // linking dependences

I based on the nice post of jonnyzzz:

https://jonnyzzz.com/blog/2018/10/29/kn-libcurl-windows/

1
  • You should've write it as a comment. Nov 28, 2020 at 9:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.