I have some code that needs to be completed in C++, and I hope to compile the C++ code into some form of dynamic library or klib, which can then be used in the Kotlin multiplatform project or as a module in a KMP project.
I hope to be able to link this part of C++ code well on different platforms. For example, on the Android platform, C++ code is compiled into a ".so" dynamic library and embedded in jar or klib, and then exported to libs when generating apk packages; On the iOS platform, it will be directly compiled into native code and embedded into the generated IPA package; On the desktop platform, it will be compiled into ".dll", ".so", ".dylib" and then embedded into a jar or generated in the jar directory where the app is located; On the web platform, it will be compiled and embedded into WASM.
Is there a universal KMP library configuration method to achieve this goal, such as creating a native module, writing C++ code directly, and configuring certain gradle.kts to automatically build klib for various platforms. Instead of writing it separately for each platform (such as creating a native module on Android and compiling it into. so by introducing Android related header files, and using Cinehop on iOS to generate dynamic libraries separately on JVM and then copying this dynamic library during packaging), it is too cumbersome! ). If this is not possible, then let the conditions be relaxed a bit. What if I don't need to use platform side C++ code or header files, such as "android.h", "Windows.h", etc., just standard algorithmic C++ code? Is there a way?
If there is such a way or if you could provide me with some simple project examples, I would greatly appreciate it!
run_konanutility gist.github.com/aSemy/076591d565867839b6009f36c3b8b3ae