Warm tip: This article is reproduced from serverfault.com, please click

With Kotlin Native, building a windows exe, can I bundle libraries ( dlls ) into the exe?

发布于 2020-01-24 19:18:33

Let's say I want to build a simple windows exe that does HTTP requests with curl.

( See example: https://github.com/JetBrains/kotlin-native/tree/master/samples/curl ).

The example above works, but in order for the exe to run, it needs to find libcurl-4.dll, either in the local dir, or e.g. in the installation dir ( e.g. C:\msys64\mingw64\lib ).

I would like to ship just the exe file, without having to provide the dll files separately. Is it possible to build the exe file with all the things it uses from the library (and transitive dependencies...) bundled into the exe file?

(This question is about if I can do this with a Kotlin 1.3.61 Native project, and how.)

Questioner
treesAreEverywhere
Viewed
0
Carlos Chuck 2020-11-30 09:34:11

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/

You need to build the static libraries using mingw (libcurl, gzip) and msys2/mingw(openssl) to use with kotlin-native compiler