Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Unable to find lib #552

@AdwayKasture

Description

@AdwayKasture

Hi,
I am new to zig and NIF, and am having a little trouble with loading a compiled c lib with Zigler.
I am attaching my repo for reference
https://github.com/AdwayKasture/jace

NIF code snippet

defmodule Jace.Bridge do
  
   @lib  {:priv, "lib/libopentui.so"}
   @header  {:priv, "include"}
  
   use Zig,otp_app: :jace,
    c: [link_lib: @lib,include_dirs: @header],
    resources: [:RendererResource,
                :OptimizedBufferResource,
                :TextBufferResource],
    nifs: [...]

  ~Z"""
 

The weird thing is the ide throws no error, if i reference a function in zig code which is not in header it throws an error (header is loaded correctly).
If i pass incompatible lib file it throws error (lib file loaded correctly).

However when I call the function through iex

i get

07:58:07.740 [error] loading module Elixir.Jace.Bridge {:load_failed, ~c"Failed to load NIF library /home/archon/work/jace/_build/test/lib/jace/priv/lib/Elixir.Jace.Bridge: 'libopentui.so: cannot open shared object file: No such file or directory'"}

same issue for test

if {:unix, :linux} == :os.type() do
  defmodule Jace.BridgeTest do
    use ExUnit.Case,async: true
    alias Jace.Bridge

    is_lib_placed =
      :jace
      |> :code.priv_dir()
      |> Path.join(Bridge.lib_path())
      |> File.exists?()

    is_header_placed =
      :jace
      |> :code.priv_dir()
      |> Path.join(Bridge.include_dir_path())
      |> Path.join("opentui.h")
      |> File.exists?()


    
    assert true == is_lib_placed 
    assert true == is_header_placed 

    test "opentui" do
      assert is_reference(Bridge.new_renderer(32,32))
      
    end
  end
else
  IO.inspect({"test aborted",:os.type()})  
end

Thanks your contribution and time.
Incase you can point me to a repo for reference that would also be helpful.
Also happy to contribute in whatever way I can.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions