martmists
07/04/2021, 11:03 AMNikky
07/04/2021, 11:07 AMbinaries { staticLib { } }
or such in your native targetmartmists
07/04/2021, 11:12 AM<project root>/lib/libname/
, and my current def file (in <project root>/src/nativeInterop/cinterop/libname.def
):
headers = lib/libname/libname.h
package = libname
compilerOpts.linux = -Ilib/libname
linkerOpts.linux = -L lib/libname -l libname
But it doesn't seem to compile the library's source files, nor does it generate the defs because apparently the lib folder is not copied to the tempdir where kotlin native compiles from.Nikky
07/04/2021, 11:33 AMBig Chungus
07/04/2021, 12:08 PMmartmists
07/04/2021, 1:02 PMplugins {
kotlin("multiplatform") version "1.5.20"
`cpp-library`
}
group = "com.martmists"
version = "1.0-SNAPSHOT"
repositories {
mavenCentral()
}
val hostOs = System.getProperty("os.name")
val isMingwX64 = hostOs.startsWith("Windows")
(properties["libraries"]!! as String).split(",").forEach {
library {
baseName.set(it)
linkage.set(listOf(Linkage.SHARED))
source.from(file("include/$it/"))
privateHeaders.from(file("include/$it/"))
publicHeaders.from(file("include/$it/"))
binaries.configureEach(CppSharedLibrary::class.java) {
if (this.isOptimized) {
// release
// Set output dir to `<project root>/lib/$it/`
// Ideally this is release when kotlin is building/running release
// and debug when kotlin is building/running debug
}
}
}
}
kotlin {
val nativeTarget = when {
hostOs == "Mac OS X" -> macosX64("native")
hostOs == "Linux" -> linuxX64("native")
isMingwX64 -> mingwX64("native")
else -> throw GradleException("Host OS is not supported in Kotlin/Native.")
}
nativeTarget.apply {
val main by compilations.getting
val portaudio by main.cinterops.creating
// Errors because it can't find the library when only source is copied
// I can't hardcode this because others also work on this and have
// this repo on a different path
// val bs2b by main.cinterops.creating
binaries {
sharedLib {
baseName = if (isMingwX64) "libkaudio" else "kaudio"
}
executable {
entryPoint = "kaudio.main"
}
}
}
sourceSets {
val nativeMain by getting
}
}
Big Chungus
07/04/2021, 1:05 PMmartmists
07/04/2021, 1:06 PMBig Chungus
07/04/2021, 1:07 PMBig Chungus
07/04/2021, 1:08 PMproject(":my-cpp-module")
martmists
07/04/2021, 1:08 PMBig Chungus
07/04/2021, 1:10 PMmartmists
07/04/2021, 1:24 PMtasks.named("build") {
dependsOn(":libraries:bs2b:build")
mustRunAfter(":libraries:bs2b:build")
}
kotlin seems to compile at the same time as cpp, meaning it won't build because the shared library will be missing
• Kotlin will fail to build with
* What went wrong:
A problem was found with the configuration of task ':stripSymbolsRelease' (type 'StripSymbols').
- In plugin 'org.gradle.nativeplatform.plugins.NativeComponentModelPlugin' type 'org.gradle.nativeplatform.tasks.StripSymbols' property 'binaryFile' specifies file '/home/mart/git/kaudio/build/lib/main/release/libkaudio.so' which doesn't exist.
Big Chungus
07/04/2021, 1:25 PMmartmists
07/04/2021, 1:25 PM* What went wrong:
Task with name ':compileKotlinNative' not found in root project 'kaudio'.
despite previous tasks saying
> Task :compileKotlinNative
...
napperley
07/04/2021, 11:37 PM// ...
cinterops.create("paho_mqtt") {
extraOpts("-libraryPath", "${System.getProperty("user.home")}/paho_mqtt_c-1.3.7/lib")
}
// ...