Hello guys. I'm trying to build a native app using...
# kotlin-native
a
Hello guys. I'm trying to build a native app using Ktor (Server/Client[Curl])... Does anybody faces with such problem during compilation?
curl 8.5.0
is installed using
brew
... Please, help! Log is in thread. >>>
Copy code
e: /Users/xxx/.konan/dependencies/apple-llvm-20200714-macos-aarch64-essentials/bin/ld.lld invocation reported errors

The /Users/arty/.konan/dependencies/apple-llvm-20200714-macos-aarch64-essentials/bin/ld.lld command returned non-zero exit code: 1.
output:
ld.lld: error: undefined symbol: curl_global_init
>>> referenced by out
>>>               /private/var/folders/ls/bgqwyh_10r9bpb10wjf9zpwc0000gn/T/konan_temp14454514086118989150/ares-poc.kexe.o:(libcurl_curl_global_init_wrapper23)
>>> did you mean: _curl_global_init
>>> defined in: /opt/homebrew/opt/curl/lib/libcurl.a

ld.lld: error: undefined symbol: curl_slist_append
>>> referenced by out
>>>               /private/var/folders/ls/bgqwyh_10r9bpb10wjf9zpwc0000gn/T/konan_temp14454514086118989150/ares-poc.kexe.o:(libcurl_curl_slist_append_wrapper27)
>>> did you mean: _curl_slist_append
>>> defined in: /opt/homebrew/opt/curl/lib/libcurl.a

ld.lld: error: undefined symbol: curl_slist_free_all
>>> referenced by out
>>>               /private/var/folders/ls/bgqwyh_10r9bpb10wjf9zpwc0000gn/T/konan_temp14454514086118989150/ares-poc.kexe.o:(libcurl_curl_slist_free_all_wrapper28)

ld.lld: error: undefined symbol: curl_easy_strerror
>>> referenced by out
>>>               /private/var/folders/ls/bgqwyh_10r9bpb10wjf9zpwc0000gn/T/konan_temp14454514086118989150/ares-poc.kexe.o:(libcurl_curl_easy_strerror_wrapper33)

ld.lld: error: undefined symbol: curl_easy_pause
>>> referenced by out
>>>               /private/var/folders/ls/bgqwyh_10r9bpb10wjf9zpwc0000gn/T/konan_temp14454514086118989150/ares-poc.kexe.o:(libcurl_curl_easy_pause_wrapper35)

ld.lld: error: undefined symbol: curl_easy_init
>>> referenced by out
>>>               /private/var/folders/ls/bgqwyh_10r9bpb10wjf9zpwc0000gn/T/konan_temp14454514086118989150/ares-poc.kexe.o:(libcurl_curl_easy_init_wrapper36)

ld.lld: error: undefined symbol: curl_easy_cleanup
>>> referenced by out
>>>               /private/var/folders/ls/bgqwyh_10r9bpb10wjf9zpwc0000gn/T/konan_temp14454514086118989150/ares-poc.kexe.o:(libcurl_curl_easy_cleanup_wrapper38)

ld.lld: error: undefined symbol: curl_multi_init
>>> referenced by out
>>>               /private/var/folders/ls/bgqwyh_10r9bpb10wjf9zpwc0000gn/T/konan_temp14454514086118989150/ares-poc.kexe.o:(libcurl_curl_multi_init_wrapper44)

ld.lld: error: undefined symbol: curl_multi_add_handle
>>> referenced by out
>>>               /private/var/folders/ls/bgqwyh_10r9bpb10wjf9zpwc0000gn/T/konan_temp14454514086118989150/ares-poc.kexe.o:(libcurl_curl_multi_add_handle_wrapper45)

ld.lld: error: undefined symbol: curl_multi_remove_handle
>>> referenced by out
>>>               /private/var/folders/ls/bgqwyh_10r9bpb10wjf9zpwc0000gn/T/konan_temp14454514086118989150/ares-poc.kexe.o:(libcurl_curl_multi_remove_handle_wrapper46)

ld.lld: error: undefined symbol: curl_multi_poll
>>> referenced by out
>>>               /private/var/folders/ls/bgqwyh_10r9bpb10wjf9zpwc0000gn/T/konan_temp14454514086118989150/ares-poc.kexe.o:(libcurl_curl_multi_poll_wrapper49)

ld.lld: error: undefined symbol: curl_multi_wakeup
>>> referenced by out
>>>               /private/var/folders/ls/bgqwyh_10r9bpb10wjf9zpwc0000gn/T/konan_temp14454514086118989150/ares-poc.kexe.o:(libcurl_curl_multi_wakeup_wrapper50)

ld.lld: error: undefined symbol: curl_multi_perform
>>> referenced by out
>>>               /private/var/folders/ls/bgqwyh_10r9bpb10wjf9zpwc0000gn/T/konan_temp14454514086118989150/ares-poc.kexe.o:(libcurl_curl_multi_perform_wrapper51)

ld.lld: error: undefined symbol: curl_multi_cleanup
>>> referenced by out
>>>               /private/var/folders/ls/bgqwyh_10r9bpb10wjf9zpwc0000gn/T/konan_temp14454514086118989150/ares-poc.kexe.o:(libcurl_curl_multi_cleanup_wrapper52)

ld.lld: error: undefined symbol: curl_multi_info_read
>>> referenced by out
>>>               /private/var/folders/ls/bgqwyh_10r9bpb10wjf9zpwc0000gn/T/konan_temp14454514086118989150/ares-poc.kexe.o:(libcurl_curl_multi_info_read_wrapper53)

ld.lld: error: undefined symbol: curl_multi_strerror
>>> referenced by out
>>>               /private/var/folders/ls/bgqwyh_10r9bpb10wjf9zpwc0000gn/T/konan_temp14454514086118989150/ares-poc.kexe.o:(libcurl_curl_multi_strerror_wrapper54)

ld.lld: error: undefined symbol: curl_easy_setopt
>>> referenced by out
>>>               /private/var/folders/ls/bgqwyh_10r9bpb10wjf9zpwc0000gn/T/konan_temp14454514086118989150/ares-poc.kexe.o:(knifunptr_libcurl39_curl_easy_setopt)

ld.lld: error: undefined symbol: curl_easy_getinfo
>>> referenced by out
>>>               /private/var/folders/ls/bgqwyh_10r9bpb10wjf9zpwc0000gn/T/konan_temp14454514086118989150/ares-poc.kexe.o:(knifunptr_libcurl42_curl_easy_getinfo)

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':linkDebugExecutableNative'.
> Compilation finished with errors
I think this is due to
libcurl4-gnutls-dev
... Related discussion.
a
Possibly it's a gcc mismatch. Kotlin/Native requires a specific version of gcc that is a bit outdated and difficult to install. I presume the curl that's installed will be compiled with a different gcc version. Do you need to use the Ktor curl library? It's not well documented but you there's a ktor-client-core dependency you can add as a commonMain dependency and it should automatically add suitable dependencies in each target. And then in src/commonMain/kotlin there's a util function for creating a Ktor client, without specifying the underlying engine. It should Just Work™️
a
The reason I'm using
curl
is that CIO has some problem with HTTPS:
Copy code
[ERROR] (ktor.application): Unhandled: GET - /company-info/19807139. Cause: kotlin.IllegalStateException: TLS sessions are not supported on Native platform.
    at 0   ares-legacy-bridge.kexe             0x100d13c67        kfun:kotlin.Throwable#<init>(kotlin.String?){} + 119 (/opt/buildAgent/work/2fed3917837e7e79/kotlin/kotlin-native/runtime/src/main/kotlin/kotlin/Throwable.kt:28:37)
    at 1   ares-legacy-bridge.kexe             0x100d0d75f        kfun:kotlin.Exception#<init>(kotlin.String?){} + 115 (/opt/buildAgent/work/2fed3917837e7e79/kotlin/kotlin-native/runtime/src/main/kotlin/kotlin/Exceptions.kt:23:44)
    at 2   ares-legacy-bridge.kexe             0x100d0d8f7        kfun:kotlin.RuntimeException#<init>(kotlin.String?){} + 115 (/opt/buildAgent/work/2fed3917837e7e79/kotlin/kotlin-native/runtime/src/main/kotlin/kotlin/Exceptions.kt:34:44)
    at 3   ares-legacy-bridge.kexe             0x100d0dd87        kfun:kotlin.IllegalStateException#<init>(kotlin.String?){} + 115 (/opt/buildAgent/work/2fed3917837e7e79/kotlin/kotlin-native/runtime/src/main/kotlin/kotlin/Exceptions.kt:70:44)
    at 4   ares-legacy-bridge.kexe             0x100cf2cd7        kfun:io.ktor.network.tls#openTLSSession#suspend(io.ktor.network.sockets.Socket;io.ktor.utils.io.ByteReadChannel;io.ktor.utils.io.ByteWriteChannel;io.ktor.network.tls.TLSConfig;kotlin.coroutines.CoroutineContext;kotlin.coroutines.Continuation<io.ktor.network.sockets.Socket>){}kotlin.Any + 259 (/opt/buildAgent/work/8d547b974a7be21f/ktor-network/ktor-network-tls/nix/src/io/ktor/network/tls/TLSClientSessionNative.kt:11:25)
    at 5   ares-legacy-bridge.kexe             0x100cf2657        kfun:io.ktor.network.tls.$tlsCOROUTINE$0.invokeSuspend#internal + 531 (/opt/buildAgent/work/8d547b974a7be21f/ktor-network/ktor-network-tls/jvmAndNix/src/io/ktor/network/tls/TLSCommon.kt:38:9)
    at 6   ares-legacy-bridge.kexe             0x100cf29df        kfun:io.ktor.network.tls#tls#suspend__at__io.ktor.network.sockets.Connection(kotlin.coroutines.CoroutineContext;io.ktor.network.tls.TLSConfig;kotlin.coroutines.Continuation<io.ktor.network.sockets.Socket>){}kotlin.Any + 331 (/opt/buildAgent/work/8d547b974a7be21f/ktor-network/ktor-network-tls/jvmAndNix/src/io/ktor/network/tls/TLSCommon.kt:33:16)
    at 7   ares-legacy-bridge.kexe             0x100cf2b97        kfun:io.ktor.network.tls#tls#suspend__at__io.ktor.network.sockets.Connection(kotlin.coroutines.CoroutineContext;kotlin.Function1<io.ktor.network.tls.TLSConfigBuilder,kotlin.Unit>;kotlin.coroutines.Continuation<io.ktor.network.sockets.Socket>){}kotlin.Any + 367 (/opt/buildAgent/work/8d547b974a7be21f/ktor-network/ktor-network-tls/jvmAndNix/src/io/ktor/network/tls/TLSCommon.kt:56:5)
    at 8   ares-legacy-bridge.kexe             0x100fe8363        kfun:io.ktor.client.engine.cio.Endpoint.$connectCOROUTINE$5.invokeSuspend#internal + 4403 (/opt/buildAgent/work/8d547b974a7be21f/ktor-client/ktor-client-cio/jvmAndNix/src/io/ktor/client/engine/cio/Endpoint.kt:235:48)
    at 9   ares-legacy-bridge.kexe             0x100fe87a7        kfun:io.ktor.client.engine.cio.Endpoint.connect#internal + 295 (/opt/buildAgent/work/8d547b974a7be21f/ktor-client/ktor-client-cio/jvmAndNix/src/io/ktor/client/engine/cio/Endpoint.kt:195:21)
Nevertheless, I'll try your suggestion. Thanks a lot.
a
Hopefully it works 🤞. But yeah, unless you need to use the curl engine on iOS there's a Darwin engine which supports TLS I believe. (Which the ktor-client-core should use under-the-hood).
a
@Artyom Gornostayev, were you lucky to find a solution? I think I have a similar issue