Skip to content

[Question] Load library from file #3

@vaclavbenes

Description

@vaclavbenes

Hi, how did you manage to load a library from disk?

  val heic = "image1.heic"
val PATH = "libheif.dylib"

    Arena.ofShared().use { arena ->

        System.load(PATH)

         val loaderLookup = SymbolLookup.loaderLookup()
         val defaultLookup = linker.defaultLookup()
         val lookup = SymbolLookup { loaderLookup.find(it).or { defaultLookup.find(it) } }

        val poiterOnFile = arena.allocateFrom(heic)


        val heifContextAlloc = lookup.find("heif_context_alloc").getOrNull() as MemorySegment

        val handleHeifContextAlloc = linker.downcallHandle(heifContextAlloc, FunctionDescriptor.of(ADDRESS))

        val pointerHeifContextAlloc = handleHeifContextAlloc.invokeExact() as MemorySegment
        println(pointerHeifContextAlloc)

I am trying to understand, but my memory segment is empty.

MemorySegment{ address: 0x600002c2a190, byteSize: 0 }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions