jmillner_
01/10/2020, 3:10 PMlibcurl.*
import? Even though I have the libcurl.def in the correct nativeInterop sub folder under src
?Kavan
01/10/2020, 7:42 PMArtyom Degtyarev [JB]
01/13/2020, 7:17 AMcinteropLibcurlMacos
, for example. Then KLIB should be created somewhere like /build/classes/kotlin/macos/main/kotlin-hands-on-intro-kotlin-native-cinterop-libcurl.klib
. Also, I’d recommend to use more recent version of Kotlin, the one from the guide can be outdated a bit.jmillner_
01/14/2020, 7:30 PMjmillner_
01/14/2020, 7:31 PMjmillner_
01/14/2020, 7:37 PMArtyom Degtyarev [JB]
01/15/2020, 7:39 AMkotlin-multiplatform
plugin(see [here](https://github.com/kotlin-hands-on/intro-kotlin-native/blob/d32de232e8ca3fe0ce31f01eb98ed229c78cd07a/build.gradle#L2
)). Currently, the latest is the 1.3.61 and is also presented in the IDEA’s Kotlin plugin. And this gap may be responsible for your problem.
Kotlin bindings are always packed as the Kotlin libraries, a.k.a KLIB(see https://kotlinlang.org/docs/reference/native/libraries.html). This format isn’t stable yet, and therefore newer library readers cannot open older libs correctly. But as far as compilation uses the project-specified version of the compiler, it is producing the correct binary. Just try to update the script version, and tell if it won’t help.jmillner_
01/21/2020, 3:05 PMArtyom Degtyarev [JB]
01/21/2020, 3:18 PMjmillner_
01/31/2020, 4:22 PMplugins {
id 'kotlin-multiplatform' version '1.3.61'
}
repositories {
mavenCentral()
jcenter()
}
kotlin {
macosX64("test") {
binaries {
executable {
entryPoint "test.main"
}
}
compilations.main {
cinterops {
curl
}
}
}
}
Which works great on MacOS, but I’d like to target both MacOS and Linuxjmillner_
01/31/2020, 4:23 PMArtyom Degtyarev [JB]
02/03/2020, 12:29 PMcinterops
block is specified per compilation, and the compilation block is per-target in itself. That’s why sharing cinterops content cannot be shared so easy.
But, there are some tricks can be done, for example, make everything depend on a host OS kind(see https://github.com/JetBrains/kotlin-native/blob/master/samples/libcurl/build.gradle.kts).jmillner_
02/05/2020, 9:28 AMheaders = curl/curl.h
headerFilter = curl/*
linkerOpts.osx = -L/usr/local/include -lcurl
linkerOpts.linux = -L/usr/include/x86_64-linux-gnu/curl -lcurl
And by build.gradle.kts looks like this:
val hostTarget = when {
hostOs.contains("Mac OS X") -> macosX64("lkug")
hostOs.contains("Linux") -> linuxX64("lkug")
else -> throw GradleException("Host OS '$hostOs' is not supported in Kotlin/Native $project.")
}
hostTarget.apply {
binaries {
executable {
entryPoint = "lkug.main"
runTask?.args("<https://www.jetbrains.com/>")
}
}
compilations["main"].cinterops {
val curl by creating {
when (preset) {
presets["macosX64"] -> includeDirs.headerFilterOnly("/usr/local/include")
presets["linuxX64"] -> includeDirs.headerFilterOnly("/usr/include/x86_64-linux-gnu")
}
}
}
mavenPublication {
pom {
withXml {
val root = asNode()
root.appendNode("name", "libcurl interop library")
root.appendNode("description", "A library providing interoperability with host libcurl")
}
}
}
}
The problem I'm having though is that when I try and build my project on a linux host, I receive an error message like Unable to find library -lcurl
My understanding is that the linkerOpts need to point to where the header files exist, so that it can point to the headers and create the kotlin binding? When checking my linux host, the destinations that I'm providing do point to the directory where curl.h
livesArtyom Degtyarev [JB]
02/05/2020, 9:38 AM/curl
in the end of your linkerOpts
. You already specified your header as curl/curl.h
.jmillner_
02/05/2020, 9:57 AM-lcurl
represent? Is that a reference to the binary on my machine? My understanding is that the -L
is -L/path/to/c/header/files
?jmillner_
02/05/2020, 9:58 AMKavan
02/05/2020, 10:06 AMjmillner_
02/05/2020, 10:09 AMjmillner_
02/05/2020, 10:45 AMjmillner_
02/05/2020, 10:46 AMjmillner_
02/05/2020, 10:47 AM-lcurl
know where to look for curl? Is it based on the PATH?Kavan
02/05/2020, 10:54 AMjmillner_
02/05/2020, 11:01 AMjmillner_
02/05/2020, 11:02 AMKavan
02/05/2020, 11:02 AMKavan
02/05/2020, 11:04 AMjmillner_
02/05/2020, 11:04 AMjmillner_
02/05/2020, 11:05 AMKavan
02/05/2020, 11:05 AMjmillner_
02/05/2020, 11:06 AMheaders = curl/curl.h
headerFilter = curl/*
linkerOpts.osx = -L/usr/local/include -lcurl
linkerOpts.linux = -L/usr/include/x86_64-linux-gnu -lcurl
Kavan
02/05/2020, 11:07 AMKavan
02/05/2020, 11:07 AMjmillner_
02/05/2020, 11:07 AMjmillner_
02/05/2020, 11:07 AMjmillner_
02/05/2020, 11:08 AMjmillner_
02/05/2020, 11:08 AMjmillner_
02/05/2020, 11:09 AMKavan
02/05/2020, 11:09 AMKavan
02/05/2020, 11:10 AMjmillner_
02/05/2020, 11:14 AMjmillner_
02/05/2020, 11:16 AMlinkerOpts.osx = -L/usr/local/include -lcurl
jmillner_
02/05/2020, 11:17 AM/usr/local/include
contains /curl
and in there is all the header files for curlKavan
02/05/2020, 11:17 AMKavan
02/05/2020, 11:22 AMjmillner_
02/05/2020, 11:25 AMhostTarget.apply {
binaries {
executable {
entryPoint = "lkug.main"
runTask?.args("<https://www.jetbrains.com/>")
}
}
compilations["main"].cinterops {
val curl by creating {
when (preset) {
presets["macosX64"] -> includeDirs.headerFilterOnly("/usr/local/include")
presets["linuxX64"] -> includeDirs.headerFilterOnly("/usr/include/x86_64-linux-gnu")
}
}
}
However I throw in there the same location for the header files, but it still works?Kavan
02/05/2020, 11:30 AMjmillner_
02/05/2020, 11:33 AMKavan
02/05/2020, 2:08 PMKavan
02/05/2020, 2:09 PMKavan
02/05/2020, 2:11 PM/usr/include/curl
folder existjmillner_
02/07/2020, 4:45 PMld.lld: error: undefined symbol: curl_easy_strerror
jmillner_
02/07/2020, 4:45 PMjmillner_
02/07/2020, 4:49 PMjmillner_
02/07/2020, 4:49 PMjmillner_
02/07/2020, 5:44 PMjmillner_
02/07/2020, 5:45 PMheaders = curl/curl.h
compilerOpts.osx = -I/usr/local/Cellar/curl/7.68.0/include <- Header Locations
compilerOpts.linux = -I/usr/local/Cellar/curl/7.68.0/include <- Header Locations
linkerOpts.osx = -L/usr/local/Cellar/curl/7.68.0/lib -lcurl <- Library Locations
linkerOpts.linux = -L/usr/local/Cellar/curl/7.68.0/lib -lcurl <- Library Locations
jmillner_
02/07/2020, 5:45 PMjmillner_
02/07/2020, 5:46 PMjmillner_
02/07/2020, 5:46 PMjmillner_
02/07/2020, 6:37 PM