I'd like to compile a C++ library (Jolt) so that I...
# kotlin-native
a
I'd like to compile a C++ library (Jolt) so that I can use it in a Kotlin/Native application. However, while I can compile Jolt using its own build scripts, this produces a library that's incompatible with Kotlin/Native (see this similar issue: https://youtrack.jetbrains.com/issue/KT-52275). I've tried compiling with a GCC installed with MSYS2, but this also produces an incompatible library. I'm trying to use the g++.exe that Kotlin/Native seems to use,
~\.konan\dependencies\msys2-mingw-w64-x86_64-2\bin\g++.exe
, but then I get this error:
Copy code
cpp.exe: fatal error: cannot execute 'cc1plus': CreateProcess: No such file or directory
I was able to compile and use this library on a Mac using Gradle's C++ plugin, but now when I try on a Windows machine I get these errors, which is pretty disappointing. I was hoping to be able to use the library on all platforms.
o
a
thanks @Oleg Yukhnevich, that sounds useful, I'll take a look!
👍 1
I managed to compile Jolt to .o object files! 🎉 Thanks for the tip @Oleg Yukhnevich. Next step is compiling them into a
.a
library...
🎉 1
o
it’s not compiling really 🙂 .a file is just specific achieve AFAIK You could look into how
skiko
builds
.a
files (but there are a lot of logic there, and I don’t really remember where it happens) you can also use
run_konan
for this:
./run_konan llvm llvm-ar macos_x64
- llvm-ar is used to create
.a
library - but Im not fully sure if it will work regarding cross compiling
a
ahh okay, cool
it doesn't look like skiko uses llvm-ar
o
Yeah, I’ve found what they use: https://github.com/JetBrains/skiko/blob/75555658e1735315df02a7b72d9b8b74ee031713/skiko/build.gradle.kts#L558 though, may be Im wrong and
llvm-ar
can not be used 🙂
a
ah cool, thanks
I'm on Windows, so it looks like that would trigger the error "Unexpected OS for native bridges linking"
o
yeah… I don’t use windows for a long time now, so it will be hard for me to help here…
a
hmmm when I run
run_konan llvm llvm-ar mingw_x64
it doesn't seem to recognise the args I've provided and just prints usage instructions
Copy code
D:\Users\Adam\.konan\dependencies\llvm-11.1.0-windows-x64-essentials/bin/llvm-ar mingw_x64 @args
OVERVIEW: LLVM Archiver

USAGE: llvm-ar [options] [-]<operation>[modifiers] [relpos] [count] <archive> [files]
       llvm-ar -M [<mri-script]

OPTIONS:
  --format              - archive format to create
    =default            -   default
...
I don’t use windows for a long time now
me neither! I was able to compile Jolt on Mac and Linux a few weeks ago.
ah, it looks like adding the Kotlin target doesn't work for llvm, so it should just be
./run_konan llvm llvm-ar
(not
./run_konan llvm llvm-ar mingw_x64
)
👍 1
o
last resort - you can look on how K/N compiler do the linking here https://github.com/JetBrains/kotlin/blob/52d6ac5ed0fe29bde09b24bdde41950811afcebb/native/utils/src/org/jetbrains/kotlin/konan/target/Linker.kt#L29 Overall, looks rather strait-forward, but I haven’t tried, so can’t help further here Good luck!
a
it's working it's working I got it working!!!!!
o
Nice! BTW, is it open-sourced, or at least will be? I would like to look on setup (for improving ffi-kotlin)
a
yes, I plan to open source the project eventually
o
Nice! Will wait for it!
that's a rough overview of the Gradle code I've got to compile the sources
and here's the demo! https://i.imgur.com/sQ7mhW3.mp4
sQ7mhW3.mp4
🎉 1
o
Nice looking demo! and bit thanks for code snippet !
🙏 1