【问题标题】:With Kotlin Native, building a windows exe, can I bundle libraries ( dlls ) into the exe?使用 Kotlin Native,构建 Windows exe,我可以将库 (dll) 捆绑到 exe 中吗?
【发布时间】:2020-01-24 19:18:33
【问题描述】:

假设我想构建一个简单的 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 项目做到这一点,以及如何做到这一点。)

【问题讨论】:

    标签: kotlin dll kotlin-native


    【解决方案1】:

    我也在学习 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 的好帖子:

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

    您需要使用 mingw (libcurl, gzip) 和 msys2/mingw(openssl) 构建静态库以与 kotlin-native 编译器一起使用

    【讨论】:

      【解决方案2】:

      您绝对可以为静态库执行此操作(请参阅this),但不适用于.dll。关于共享库捆绑,我只推荐你看这个question。大致相同,但有点笼统。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-06-05
        • 1970-01-01
        • 1970-01-01
        • 2012-08-20
        • 2012-07-23
        相关资源
        最近更新 更多