使用 Kotlin Native 构建 windows exe,我可以将库 ( dll ) 捆绑到 exe 中吗?
With Kotlin Native, building a windows exe, can I bundle libraries ( dlls ) into the exe?
假设我想构建一个简单的 windows exe,它使用 curl 执行 HTTP 请求。
(参见示例:https://github.com/JetBrains/kotlin-native/tree/master/samples/curl)。
上面的示例有效,但为了使 exe 成为 运行,它需要在本地目录中找到 libcurl-4.dll
,或者例如在安装目录中(例如 C:\msys64\mingw64\lib
)。
我只想发送 exe 文件,而不必单独提供 dll 文件。是否可以构建 exe 文件,并将它从库中使用的所有东西(和传递依赖项......)捆绑到 exe 文件中?
(这个问题是关于我是否可以用 Kotlin 1.3.61 Native 项目来做这个,以及如何做。)
您绝对可以为静态库执行此操作(参见 this), but not for the .dll
. About the shared library bundling, I would just recommend you to see this question。它大致相同,但有点笼统。
我也在研究 Kotlin,花了很多时间才明白如何处理 def 文件、包含和静态库。
我做了一个例子,说明如何在 kotlin-native 上使用静态库(带 gzip 的 curl 和使用 mingw 编译的 SSL 支持)。这样你就不需要为你的应用程序提供 dll 文件
https://github.com/carlosrafp/Libcurl-Kotlin-Native-standalone
在libcurl.def文件中你可以看到:
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
我基于 jonnyzzz 的好 post:
https://jonnyzzz.com/blog/2018/10/29/kn-libcurl-windows/
您需要使用 mingw(libcurl、gzip)和 msys2/mingw(openssl) 构建静态库以与 kotlin-native 编译器一起使用
假设我想构建一个简单的 windows exe,它使用 curl 执行 HTTP 请求。
(参见示例:https://github.com/JetBrains/kotlin-native/tree/master/samples/curl)。
上面的示例有效,但为了使 exe 成为 运行,它需要在本地目录中找到 libcurl-4.dll
,或者例如在安装目录中(例如 C:\msys64\mingw64\lib
)。
我只想发送 exe 文件,而不必单独提供 dll 文件。是否可以构建 exe 文件,并将它从库中使用的所有东西(和传递依赖项......)捆绑到 exe 文件中?
(这个问题是关于我是否可以用 Kotlin 1.3.61 Native 项目来做这个,以及如何做。)
您绝对可以为静态库执行此操作(参见 this), but not for the .dll
. About the shared library bundling, I would just recommend you to see this question。它大致相同,但有点笼统。
我也在研究 Kotlin,花了很多时间才明白如何处理 def 文件、包含和静态库。
我做了一个例子,说明如何在 kotlin-native 上使用静态库(带 gzip 的 curl 和使用 mingw 编译的 SSL 支持)。这样你就不需要为你的应用程序提供 dll 文件
https://github.com/carlosrafp/Libcurl-Kotlin-Native-standalone
在libcurl.def文件中你可以看到:
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
我基于 jonnyzzz 的好 post:
https://jonnyzzz.com/blog/2018/10/29/kn-libcurl-windows/
您需要使用 mingw(libcurl、gzip)和 msys2/mingw(openssl) 构建静态库以与 kotlin-native 编译器一起使用