Giter VIP home page Giter VIP logo

Comments (3)

artdfel avatar artdfel commented on June 11, 2024

Hello, @dickensas! First of all, I got to remind you about Kotlin/Native issue tracker migration(see #4079). This particular problem seems to be more likely a question rather than a bug, so maybe it could be asked on the #kotlin-native slack channel.
About the error itself. The void * construction from C is being mapped to the special COpaquePointer type(see details here). As the documentation says, such pointer should be explicitly cast to necessary type using .reinterpret() method. In this case, it should look somehow like this:

memScoped {
    val lib = alloc<libnative_ExportedSymbols>().apply {
         libnative_symbols()
    }
    println(lib.kotlin.root.example.forIntegers.reinterpret<<CFunction<() -> String>>().invoke())
}

Also, I just want to ask about reasons of choosing such uneasy approach. Using a .klib might be more relevant here, or I'm missing something?

from kotlin-native.

dickensas avatar dickensas commented on June 11, 2024

I did definitely referred the code for libcurl and curl and understood in the past

The reason I am going for direct DLL is that I am trying create .pyd for python without a C stub

Documentation Reference - .dll -> .pyd

Regarding your code, I could not compile it in kotlin 1.3.72

Therefore I went for this code, Above main method I declared typealias

  typealias SomeFun = CFunction<() -> CPointer<ByteVar>?>
  ....
  ....
  val s = lib.kotlin.root.example.someLibraryMethod?.reinterpret<SomeFun>()    
  println(s?.invoke())

But I am getting null

This is the GitHub URL Kotlin DLL - to - Kotlin

from kotlin-native.

dickensas avatar dickensas commented on June 11, 2024

This technique is working, therefore I close this issue

memScoped {
     val lib:CPointer<libmyext_ExportedSymbols>? = libmyext_symbols()
     println(lib!!.pointed.kotlin.root.example.getHello!!.reinterpret<SomeFun>()!!()!!.toKString())
}

Output

> Task :runDebugExecutableLibpymyext
That is from Kolin DLL

BUILD SUCCESSFUL in 9s

from kotlin-native.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.